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
wajhiuddinAsked:
Who is Participating?
 
yehudahaConnect With a Mentor Commented:
i think this will do it

put your values in this lines:

strUsername = "user name"
strComputer = "Computer Name"
' ------ SCRIPT CONFIGURATION ------
strUsername = "user name"
strComputer = "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

0
 
solomonacquahCommented:
0
 
solomonacquahCommented:
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

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
wajhiuddinAuthor Commented:
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
0
 
yehudahaCommented:
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

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


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.