# Vb Code to lock computer after certain time.



## anandharaja (Jun 13, 2012)

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 (Jun 13, 2012)

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)

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 (Jun 13, 2012)

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)

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)

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 (Jun 15, 2012)

I abhor VB, but the thing can be done in VB.NET & C#.NET as


```
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.


----------

