DIGIT-ARC read-only archive · snapshot: July 23, 2026

Vb Code to lock computer after certain time.

7 posts · originally from https://geek.digit.in/community/threads/vb-code-to-lock-computer-after-certain-time.158495/

anandharaja
anandharaja Original post #1
Jun 13, 2012 at 8:09 PM
hi
i want VB code to lock computer based on time set (like 1 or 2 hour).
and also i want to lock desktop wallpaper.
any one give code please.
clmlbx
clmlbx #2
Jun 13, 2012 at 8:22 PM
any specific reason to use vb..

your tasks can easily be done with task scheduler & group policy editor.. available on all windows pcs
anandharaja
Jun 13, 2012 at 8:27 PM
i like to create in UI friendly. i googled about that but all of did just lock the screen, but i want specify the time as per my need.
000Orga
000Orga #4
Jun 13, 2012 at 10:25 PM
There's also some freeware that can do the job of locking the computer too. I think it has the same VB code if I'm not mistaken..
anandharaja
Jun 14, 2012 at 8:40 AM
Thanks for your suggestion, see the form i want to code that form.
*lh5.googleusercontent.com/-9w4D5ND1a0s/T9lVeMxPAVI/AAAAAAAAAdo/HwzC3ts-Th0/s451/lock%2520screen.jpg
i found lots of tutorial to lock the computer screen, but what i want is to lock the screen in specified time any one created that before in school or college projects.
anandharaja
Jun 15, 2012 at 11:10 AM
i want to save the check box state (checked or unchecked). whenever i closed and open the form the check boxes are not selected how to save the settings?
nbaztec
nbaztec #7
Jun 15, 2012 at 5:22 PM
I abhor VB, but the thing can be done in VB.NET & C#.NET as

Code:
Process.Start(@"C:\WINDOWS\system32\rundll32.exe",  "user32.dll,LockWorkStation");

Which is nothing but calling rundll32.exe with a set of parameters, which in turn hooks to user32.dll ergo calling LockWorkStation() of the Windows API.

If this is too much hassle, you can opt to dllimport user32.dll's LockWorkStation() directly into your project.

Regarding post #2,

If the form is the Main form, you'll have to use persistence to manually read & write settings to the disk. If the form is a secondary/child form, you can hook it's OnClosing() event to instead Hide() it, ..... or you can save its settings in the parent form.