Guys I just want to inquire if it's possible to create a program that can lock not only the application but the whole system(PC)? What I want is that, if my application wasn't used within a specified time frame, it will automatically o\lock the whole computer and it can only be unlocked by a password. Any idea shall be appreciated... Thanks

You could make it where you log the user off of his account like so:

Shell("shutdown -l")

Then you could make it where you disable the keyboard for as long as you want:

'Add This Before Any Sub
Public Declare Function apiBlockInput Lib "user32" Alias "BlockInput" (ByVal fBlock As Integer) As Integer

'Add This on a Button or Anything You Would Like
apiBlockInput(1)
System.Threading.Thread.Sleep(3000) 'Each 1000 = 1 second
apiBlockInput(0)

Hope this gives you an idea and happy coding!

Comments
when did shutdown become log off?

To do this you either have to replace shell (explorer.exe) with one that you control (Doesn't support Alt+Ctrl+Delete) as AndyPants pointed out or write a program that will enforce screen saver settings (disable changing the duration before screen saver kicks in).
It's not the perfect solution, as somebody can change the inactivity time for screen saver from registry, but your program can reset it in the next reboot or with a timer whenever you wish it to.

Simply use the built-in screen saver lock after some minutes of inactivity. Adam_K has just explained the stress in achieving what you want.

Edited 5 Years Ago by Netcode: n/a

Guys you have been very helpful. But then, I used this code;

Public Declare Function apiBlockInput Lib "user32" Alias "BlockInput" (ByVal fBlock As Integer) As Integer

however it did not seem to work, I also added this code within a button;

apiBlockInput(1)
System.Threading.Thread.Sleep(3000) 'Each 1000 = 1 second
apiBlockInput(0)

..

Could you please explain a little bit about this code, I couldn't really understand what each line of code means. It would be better if I know something about them...
Thanks to;
NetJunkie, Reverend_Jim, Netcode, Adam_k...
And please also tell me about that screensaver thingy, how do I take control of it programatically?

Simply use the built-in screen saver lock after some minutes of inactivity. Adam_K has just explained the stress in achieving what you want.

In reference to your reputation comment, "shutdown -l" is the shell command to Log Off of the user that is currently signed in. Just like "shutdown -r" restarts the computer and "shutdown -s" shuts the computer down completely.

Comments
You are right.
This article has been dead for over six months. Start a new discussion instead.