且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在WinForm上创建安全的身份验证表单

更新时间:2023-09-11 18:36:46

这将是对OS的滥用,因此也难怪OS不允许您这样做.常规的Forms应用程序.无论如何,您将无法禁用Ctrl + Alt + Del,然后显示任务管理器并结束过程.



但是,请参见以下讨论:
c#程序ctrl-alt-del屏幕窗口7 [ ^ ].

例如,对于Web应用程序,有一个Kiosk模式.请参阅:
使用C#以Kiosk模式运行网站 [
This would be abuse of the OS, so no wonder that OS won''t allow you to do it by a regular Forms application. Any in any case, you won''t be able to disable Ctrl+Alt+Del followed by showing the Task Manager and ending of your process.



However, please see this discussion:
c# program ctrl-alt-del screen windows 7[^].

For a Web application, for example, there is a Kiosk Mode. Please see:
Running a Web Site in Kiosk Mode with C#[^].

—SA


已解决桌面问题

1)描述WinApi包装器
Solved with desktops

1) describe WinApi wrappers
[StructLayout(Sequental, Unicode)]
public struct SECURITY_ATTRIBUTES{     public Int32 nLength, SecurityDescriptor, bInheritHandle; }


描述对WinApi函数OpenDesktop,SwitchDesktop,SetThreadDesktop的引用


describe referenses to WinApi functions OpenDesktop, SwitchDesktop, SetThreadDesktop

[DllImport("user32.dll", Unicode)]
public static extern IntPtr CreateDesktop (string,string,Int32,UInt32,UInt32,IntPtr);



2)什么时候需要显示登录表单,
2a)创建登录桌面(如果存在,则仅打开)



2) when need to show Login Form,
2a) create login desktop (if it exists, it only open )

string dskName = "Logon desktop";
SECURITY_ATTRIBUTES sAtt = new SECURITY_ATTRIBUTES(){nLength=Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)), bInheritHandle=1};
sAtt.lpSecurityDescriptor =0;

IntPtr hglobal = Marshal.AllocHGlobal(Marshal.SizeOf(sAtt));
Marshal.StructureToPtr(sAtt, hglobal, false);

IntPtr logonDsk = CreateDesktop (dskName, null, 0, 1, 0x10000000, hglobal);

Marshal.FreeHGlobal(hglobal);



2b)创建新线程和登录表单



2b) create new thread and login form

Thread thread = new Thread(new ThreadStart(()=>
{
   logonDsk = createLoginDesk();
   SetThreadDesktop(logonDsk);
   SwitchDesktop(logonDsk);

loginForm = new LoginForm();
dlgResult = loginForm.ShowDialog();

var newdsk = OpenDesktop("Default",1,true,0x10000000);
SetThreadDesktop(newdsk);
SwitchDesktop(newdsk);
}));



3b)等待线程完成,然后从loginForm获取数据

附:解决方案将有更详细的说明.



3b) wait for finishing thread, after that get data from loginForm

p.s.: solution will be write in more details.