×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBScript FAQ

Scripting for the Enterprise

Reset or synchronize local admin password on workstations or servers by markdmac
Posted: 9 Aug 06 (Edited 13 Jun 12)

Through attrition, local admin passwords on domain computers tend to get out of sync. The below script will read a text file of domain computer names and syncronize the admin password on each listed machine. The script generates reports of the success and failures.

Like many of my scripts, this one uses a WSLIST.TXT file. You can easily generate that file using the script I provide in another of my FAQs FAQ329-4871: How can I run scripts against multiple computers and gather information?.

CODE

Option Explicit
'==========================================================================
'
' NAME: resetAdminPasswordsonPC.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE : 4/21/2004
' COPYRIGHT (C) 2004, All Rights Reserved
'
' COMMENT: Resets the local admin password on domain computers.
' Requires a list of workstation names called wslist.txt.
' MODIFICATIONS:
' 7/9/2006- Added event log code
'
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
' OF THIS CODE OR INFORMATION.
'
'==========================================================================


On Error Resume Next
Const EVENT_SUCCESS = 0
Dim WSHShell, oFSO, oFailureReport, oSuccessReport, oTextStream, oAdminID, RemotePC, strComputerName
Dim adminPassword

Set WSHShell = CreateObject("Wscript.Shell")
Set oFSO=CreateObject("Scripting.FileSystemObject")

If Not oFSO.FolderExists("c:\scripts\lists") Then
oFSO.CreateFolder("c:\scripts")
oFSO.CreateFolder("c:\scripts\lists")
End If

If oFSO.FileExists("c:\scripts\lists\failed.txt") Then
oFSO.DeleteFile("c:\scripts\lists\failed.txt")
End If

If oFSO.FileExists("c:\scripts\lists\success.txt") Then
oFSO.DeleteFile("c:\scripts\lists\success.txt")
End If


set oFailureReport=oFSO.createtextfile("c:\scripts\lists\failed.txt")
set oSuccessReport=oFSO.createtextfile("c:\scripts\lists\success.txt")




'open the data file

Set oTextStream = oFSO.OpenTextFile("wslist.txt")

If Err Then
MsgBox vbTab & vbTab & "WSLIST.TXT Source File Required" & vbCrLf & "Create the file, place in the same directory as this script and try again."
WScript.Quit
End If

'make an array from the data file

RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close


For Each strComputername In RemotePC
'Goto the local Admin account of the machine
set oAdminID = GetObject("WinNT://" & strComputername & "/administrator,user")
'Check for error and record in case of failed attempt
If Err Then
ReportError()
Err.Clear
Else
adminPassword = "putnewpasswordhere"
oAdminID.SetPassword adminPassword
oAdminID.SetInfo
oSuccessReport.WriteLine strComputername & " Admin Password was reset."
End If
WSHShell.LogEvent EVENT_SUCCESS, _
"Admin password reset by a script from The Spider's Parlor. http://www.thespidersparlor.com/vbscript", "\\" & strComputername
Next

'Close all open files

oFailureReport.close
oSuccessReport.close

'Let us know its finished

msgbox "Done"

set oFSO = nothing
set oAdminID = Nothing
set oTextStream = nothing
set oSuccessReport = nothing
set oFailureReport = nothing

Sub ReportError()
oFailureReport.WriteLine strComputername & " could not be reset. Check that it is powered on." & Err.Number
End Sub

Back to VBScript FAQ Index
Back to VBScript Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close