I would like to write a small application that unlocks the workstation. To put the specs of what I need very simple: Have an exe that runs and at a defined time (let's say midnight) unlocks the workstation.
Of course the application knows the user and password of the logged on account.
I know of the LogonUser API and have tried using it but failed.
Does anyone have a solution, code excerpt that actually works for this issue?
I am targeting NT5 OSes.
Well, since people started asking what is the reason: I am working on a desktop sharing application and I want to add the feature of unlocking the workstation. Having the very small and simple app to unlock the station at a defined time is in order to separate the problem and to avoid the integration details.
Just so you have an answer for this instead of people leaving answers which might be better off as comments.
This is certainly possible, though as many people have already said it's not really wise, what happens if someone is walking by the computer as it unlocks, how long do they have to play around, etc?
Anway, apart from suggesting you have a service to do any work that you want on hte computer, or even remotely connecting to the computer to do work you might be able to make user of the following information. (as for 'code excerts' you can make it yourself)
http://www.paralint.com/projects/aucun/ is a GINA implementation which will be able to give you rights to log on even if someone else has already logged on. Look into it it might be what you're looking for and is a lot safer than unlocking the workstation at a certain time.
As an alternative, look into writing your own GINA implementation that will do an unlock at a scheduled time.
Information on GINA
http://msdn.microsoft.com/en-gb/magazine/cc163803.aspx
http://msdn.microsoft.com/en-us/magazine/cc163786.aspx
After you've unlocked the desktop I'm pretty sure you're going to want to lock it again.
http://www.codeproject.com/win32/AntonioWinLock.asp
Just to add another lead (an not have any judgment), autoit (a scripting Windows language) may have an answer, as described in this thread:
How to unlock an Xp desktop
And I just found another scenario where one might want to unlock a desktop ;)
Let your app run as a service, then you do not need user/password as that is set up with the service.
For my situation I needed to be able to restore the console session after I've disconnected my terminal session (I'm connecting to a WinXPe kiosk with a touchscreen, but no keyboard).
Here's a command line solution I found to work. Instead of closing my session window to disconnect, I run a batch file with the following line. My session is closed and the console session is restored unlocked.
automatically unlock workstation after terminal session on WinXP
tscon.exe 0 /dest:console
for Windows Vista/7 the console session number has changed from 0 to 1, so you need to use
tscon.exe 1 /dest:console
Source link: http://arstechnica.com/civis/viewtopic.php?f=15&t=69113