Link to home
Start Free TrialLog in
Avatar of MadridEspana
MadridEspana

asked on

Programmatically Unlocking a Windows200 PC

How can I unlock a Win2K computer via script or Visual Basic?
I tried disabling Ctrl + Alt + Del at the group policy so when locking the PC it stays on the screen when you have to enter the password to unlock and then use Sendkeys but that does not work.
We reboot our servers on Saturday mornings and then have to start a program again on this PC. Starting the program with the script I wrote works great if the PC is not locked.
Please help.
Thanks.
Avatar of cookre
cookre
Flag of United States of America image

If the program doesn't use any user-specific features, e.g., HKCU hive, network connection, mapped drive letters, then you could use a service to start it at boot without having to wait for a user logon.

Avatar of travisjhall
travisjhall

By "unlock a Win2K computer", do you mean "log on to a Win2K computer"? As in, after reboot, you hit Ctrl+Alt+Del to bring up the logon dialog, enter and username and password, and hit OK to start using the computer?

If so, there's no need to use script or VB to do this (and you may not be able to, anyway. I'm not sure it is possible, and it is certainly somewhat difficult even if it is possible.) Windows 2000 has a built-in feature to do this.

The feature you need is described in MSDN article Q253370. To summarise, you need to edit the registry. Find registry key HKEY_LOCAL_MACHINE\SOFTWARE\WindowsNT\CurrentVersion\WinLogon. Set the DefaultLogon, DefaultPassword and DefaultDomainName values to match whatever logon you wish to use, and set AutoAdminLogon (a REG_DWORD value, in case you need to create it) to 1. (The article doesn't mention DefaultDomainName, but if you are trying to log on using a domain account you will need to set this, I believe.) After doing this, the computer should attempt a logon automatically following a reboot - no programming necessary.

I would advise using Regedt32.exe to set appropriate security permissions on the WinLogon key, to make sure that nobody who shouldn't know it can read you admin logon password out of it.

Also, cookre is right, you can adopt various tactics to run your program as a service, but this isn't always an ideal approach (especially if said program is a third-party product that doesn't work well that way).
That's a perfectly reasonable thing to do.  As a matter of fact, I do that on my home boxes (the lazy way with TweakUI).

In your environment, you may want to modify your code to do a logoff when the program is done, however, so you don't leave a logged on box unattended.
There are some programs which need to be left running on a server sometimes. We have servers here where I work that are set to logon and run a program automatically and just keep running said program. These are third-party products which aren't suited to being run as a service. (I tend to write my own stuff such that it runs as a service if this is required.) However, our servers are kept in a locked server room. It's not an easy thing to do to physically access those servers, so we aren't terribly worried about the systems having a desktop.

Even if you can't prevent physical access to the machines, though, it is a simple matter to set the machine to automatically lock the desktop, without logging off.
Avatar of MadridEspana

ASKER

The server is continually running processes. Due to our ERP package MRP and other manufacturing programs can be scheduled to run at night but in order to run a user has to be logged on to the ERP package. You cannot run this as a process. On Saturdays we reboot our servers and in order to this process to be running I wrote a program that uses Sendkeys to log on and click on the Deferred Processing screen program. It works fine if the server is not locked. However the server is supposed to be locked when we are not there. I tried logoff instead of reboot and the logoff batch file works as long as the computer is not locked. It seems that nothing works when the computer is locked.
ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How are you locking the Server? Have you got something set up which locks it immediately upon logon, or is it a timed lock after a certain period of inactivity?

If it is acceptable for there to be a short delay between logging on and locking, can you just set your screen-saver settings to lock the computer after a certain period of inactivity? Then, you set up an automatic logon (as I described previously), activate the Deferred Processing screen program with a shortcut in the appropriate startup folder or an autorun setting in the registry, and you should have everything up and running before the computer locks the screen.