How do I lock the workstation from a windows service?
Posted
by Brad Mathews
on Stack Overflow
See other posts from Stack Overflow
or by Brad Mathews
Published on 2010-03-17T23:16:21Z
Indexed on
2010/03/17
23:21 UTC
Read the original article
Hit count: 398
Hello,
I need to lock the workstation from a windows service written in VB.Net. I am writing the app on Windows 7 but it needs to work under Vista and XP as well.
User32 API LockWorkStation does not work as it requires an interactive desktop and I get return value of 0.
I tried calling %windir%\System32\rundll32.exe user32.dll,LockWorkStation from both a Process and from Shell, but still nothing happens.
Setting the service to interact with the desktop is a no-go as I am running the service under the admin account so it can do some other stuff that requires admin rights - like disabling the network, and you can only select the interact with desktop option if running under Local System Account.
That would be secondary question - how to run another app with admin rights from a service running under Local System Account without bugging the user.
I am writing an app to control my kids computer/internet access (which I plan to open source when done) so I need everything to happen as stealthily as possible.
I have a UI that handles settings and status notifications in the taskbar, but that is easy to kill and thus defeat the locking. I could make another hidden Windows Forms app to handle the locking, but that just seems a rather inelegant solution.
Better ideas anyone?
Thanks! Brad
© Stack Overflow or respective owner