问题
How may I completely lock the system via C-Sharp code like the
Bundespolizei-Virus does? I´m trying to secure my computer with a little software that locks the system when nothing happens for 5 minutes and only unlocks when the user entered the right password.
It´s not my goal to write an own virus or something like that, it´d just be nice to know how.
I don´t want to lock it as windows does because I want to show my own User Interface.
It´d also be useful when writing a program for public computers where users only should work with this program and have no possibilities to access the operating system in any way.
回答1:
On Windows, just set a screensaver password with a timeout for 5 minutes. That's as secure as you can get.
[Updated]
Ah, you've updated the question. So you don't want the standard windows lock screen? Well it depends on how secure you want it to be. As I said in a comment above, you'll not be able to intercept CTRL+ALT+DEL unless you hook into the security subsystem. You used to be able to do this by writing a custom GINA DLL, but since Vista this is deprecated. Now you need to do this with custom "Credential Providers";
http://msdn.microsoft.com/en-us/magazine/cc163489.aspx
If you don't want to take this route, you could also use "Policy" to lock a machine down to a point, but there's always a way around a user-mode app. If the user can bring up task manager then they can run anything on the box usually.
回答2:
You can use this piece of code to lock the workstation, using API from user32.dll:
[DllImport("user32.dll", SetLastError = true)]
static extern bool LockWorkStation();
Usage:
bool result = LockWorkStation();
if (result == false)
{
// An error occured
throw new Win32Exception(Marshal.GetLastWin32Error());
}
References:
- Lock computer using c# in window application
- Lock, Sleep or Hibernate Windows using C#
来源:https://stackoverflow.com/questions/12858961/how-to-lock-system