' Usage: cscript script.vbs computername
' For Example: cscript script.vbs servername
sComputer=ucase(wscript.arguments(0))
set objNetwork=CreateObject("Wscript.Network")
sComputer=objNetwork.ComputerName
' New Administrator Name
sNewName=""
' New Password to be set
strPassword=""
set ocomputer=GetObject("WinNT://"&sComputer)
if err.number <> 0 then
wscript.echo "Couldn't connect to " & sComputer & ". Error: " & cSTR(Hex(err.number)) & " " & err.description
err.clear
wscript.quit
end if
for each oUser in oComputer
if oUser.class="User" then
if right(GetSid(oUser.objectSID),4)="-500" then set oAdmin=ouser
if right(GetSid(oUser.objectSID),4)="-500" then oUser.SetPassword strPassword
if right(GetSid(oUser.objectSID),4)="-500" then oUser.SetInfo
end if
next
if TypeName(oAdmin) <> "Object" then
wscript.echo "Couldn't get admin account on " & sComputer & ". Error: " & cSTR(Hex(err.number)) & " " & err.description
err.clear
wscript.quit
end if
set oNew=oComputer.MoveHere (oAdmin.ADsPath,sNewName)
if err.number <> 0 then
wscript.echo "Error setting password on " & sComputer & ". Error: " & cSTR(Hex(err.number)) & " " & err.description
err.clear
end if
wscript.echo sComputer & " - done."
Function GetSid(bSID)
dim arrSubAut(25)
strSID="S"
strTmp=Cstr(hex(ascw(mid(bSid,1))))
arrSubAut(1)=CDbl(right(strTmp,2))
arrSubAut(2)=CDbl(left(strTmp,2-4+len(strTmp)))
for intx = 3 to len(bSid)/2
arrSubAut(intX)="&H"&Cstr(hex(ascw(mid(bSid,intx*2))))&CStr(hex(ascw(mid(bSid,(intx*2)-1))))
next
for intx = 1 to len(bSid)/2
strSID=strSID&"-"&CStr(CDbl(arrSubAut(intx)))
next
GetSid=strSID
End Function