Friday, May 9, 2008

Changing Local Administrator password through domain

Hi,

You can change Local machines Administrator password through network. Use the below script and save it as .vbs (eg. changepwd.vbs). Open the saved file, it will asks you the new password to change.

Note: Before doing this open a new notepad file and create headers and the machine list which you have to change the password. (Eg as follows)

Name Type Description
Computer-abc Computer owner-abc

Save this file as servers.txt

Password Change Script:

Dim fsoIn, fsoOut
Dim inFile, outFile
Dim arrComputerNames
Dim objUser
Dim strComputer
Dim newPassword
Dim ErrorOccurred
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const inFilename = "servers.txt"
Const outFilename = "ChangePwd.log"
On Error Resume Next
ErrorOccurred = False
newPassword = Inputbox ("Please enter the new password.")

Set fsoIn = CreateObject("scripting.filesystemobject")
Set inFile = fsoIn.OpenTextFile(inFilename, ForReading, True)
inFile.Skipline

Set fsoOut = CreateObject("scripting.filesystemobject")
Set outFile = fsoOut.OpenTextFile(outFilename, ForAppending, True)
outFile.writeline (Now & vbTab & "Starting script...")

While Not inFile.AtEndOfStream
arrComputerNames = Split(inFile.Readline, vbTab, -1, 1)
strComputer = arrComputerNames(0)

Set objUser = GetObject("WinNT://" & strComputer & "/Administrator, user")
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & "Error connecting to " & strComputer & " --- " & Err.Description
Err.Clear
ErrorOccurred = True
Else
objUser.SetPassword newPassword
objUser.SetInfo
If Err.Number <> 0 Then
outFile.writeline Now & vbTab & "Error setting password for " & strComputer & _
"\Administrator" & " --- " & Err.Description
Err.Clear
ErrorOccurred = True
Else
outFile.writeline (Now & vbTab & "Password set for " & strComputer & "\Administrator")
End If
End If
Wend

outFile.writeline (Now & vbTab & "Ending script...")
inFile.close
outFile.close

If ErrorOccurred Then
msgbox "Script completed with errors. Please check the log file."
Else
MsgBox "Script completed successfully."
End If


You can also download the same script in .txt format from the below address:
http://cid-7b9af3f31c9b858c.skydrive.live.com/browse.aspx/Lokesh?uc=1

By,
Lokesh G _L-
"Nobody is Perfect,
I AM A LEARNER"

No comments: