views:

2377

answers:

4

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.

+3  A: 

Let your app run as a service, then you do not need user/password as that is set up with the service.

mm2010
+5  A: 

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 there is a cleaner 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

PintSizedCat
-1 for implying all cleaners are dishonest
finnw
Thanks for the answer. Most accurate up to now.
Dan Cristoloveanu
+1  A: 

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 ;)

VonC
+2  A: 

Hmm, sorry that this should be a comment (I don't have a 15 status) but I am completely dismayed that the entire world seems to be obsessed with advising that auto-unlocking of workstations is a bad idea (and following with reasons why) when there are plenty of good reasons for wanting to do it.

I've been looking for code which will unlock my workstation (just an XP box on a workgroup) AT HOME. In my ROOM. Christ, if anyone manages to get to that PC without my knowledge, the fact they can log in is the last of my problems!

Lets face it, if someone really wants to bugger your machine, it'll be easy unless you take care all the time! Many people don't have a short lock timeout on their screensaver - the easiest way to lock your PC.

Sorry for the rant, it's just boiled over now.

Matt W