Link to home
Start Free TrialLog in
Avatar of wajhiuddin
wajhiuddin

asked on

VB Script to unlock locla admn account

Is there a way to programmatically unlock the Admin account if it is locked?

Is there a way to configure things so that Admin will not lock?  Is there a way to programmatically configure it this way?


Thanks

Wajhi
ASKER CERTIFIED SOLUTION
Avatar of yehudaha
yehudaha
Flag of Israel 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
This should use the local computer account.
Set objNetwork = CreateObject("Wscript.Network")
 
strLocalComputer = objNetwork.ComputerName
 
strComputer = strLocalComputer
 
Set UserObj = GetObject("WinNT://" & strcomputer & "/" & "Administrator")
UserObj.IsAccountLocked = 0
UserObj.SetInfo
 
wscript.echo

Open in new window

Avatar of wajhiuddin
wajhiuddin

ASKER

Great, Thanks  Any way we can add some so it will ask a computer name??
We have several computers and user may screw up the script by adding a computer name??
Also can we  have setup account so it will never unlock

Thanks

Wajhi
script will ask for computer name
' ------ SCRIPT CONFIGURATION ------
strUsername = "user name"
strComputer = inputbox("enter Computer Name")
' ------ END CONFIGURATION ---------
 
set objUser = GetObject("WinNT://" & strComputer & "/" & strUsername)
if objUser.IsAccountLocked = True Then
   objUser.IsAccountLocked = False
   objUser.SetInfo
   WScript.Echo "Account unlocked"
Else
   WScript.Echo "Account not locked"
end If

Open in new window

Thanks This works . If I can get the script to get account never locks this will be great