Error DataBase-One Place all Solutions Forums Blog Glossary    Contact Us
Search  
   
Browse by Category
Error DataBase-One Place all Solutions .: Operating Systems .: Windows Operating Systems .: Windows Scripts and Batch Files .: VBScript to Change Admin Password on a list of Computers

VBScript to Change Admin Password on a list of Computers

Create a text file listing one computer name per line, and this script will change the local Administrator password on each (the password is hardcoded into the script).

________________________________________________________________________________________________


' --------------------------------------------------------
'           ScriptingAnswers.com ScriptVault
' --------------------------------------------------------
' Entry title: Change admin password on multi computers
'      Author: Don Jones
'      E-mail: don@scriptinganswers.com
'
' Brief desscription:
' Reads a list of computer names from a file (one name per
' line), and changes the local Admin password on each.
'
'
'
' --------------------------------------------------------
' Version history:
' 1.0   02/17/2006  Initial release
'
' --------------------------------------------------------
' The user of this script accepts all responsibility For
' reviewing, testing, and using it, and specifically
' holds harmless ScriptingAnswers.com, SAPIEN Technologies,
' and the script's original author from any damages which
' result from the use of this script, including any
' direct, consequential, or indirect damages which may
' result.
' --------------------------------------------------------


' --------------------------------------------------------
' DOCUMENTED DEPENDENCIES
' Things this script relies on or assumes are already
' in place, apart from things which are built into
' WinXP or later:
'  Relies on WinXP or Win2003.
' --------------------------------------------------------

 

' --------------------------------------------------------
' VARIABLE DECLARATIONS
' --------------------------------------------------------
Option Explicit
Dim strFile
Dim objFSO, objTS, strComputer


' --------------------------------------------------------
' STATIC VARIABLE ASSIGNMENTS
' --------------------------------------------------------
strFile = "C:\computers.txt"

 

' --------------------------------------------------------
' MAIN SCRIPT CODE
' --------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFile) Then
 Set objTS = objFSO.OpenTextFile(strFile)
 Do Until objTS.AtEndOfStream
  strComputer = objTS.ReadLine
  
  'do something with strComputer
  If TestPing(strComputer) Then
  
   On Error Resume Next
   Dim objAdmin
   Set objAdmin = GetObject("WinNT:\\" & strComputer & "\Administrator,user")
   
   If Err = 0 Then
    objAdmin.SetPassword "P@ssw0rd!"
    objAdmin.SetInfo
   Else
    WScript.Echo strComputer & " skipped: " & _
     Err.Description
   End If
   On Error GoTo 0
   
  End If
  
 Loop
End If

objTS.Close
WScript.Echo "Complete"

 

' --------------------------------------------------------
' SUBS AND FUNCTIONS
' --------------------------------------------------------
Function TestPing(sName)
 Dim cPingResults, oPingResult
 Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery("SELECT * FROM Win32_PinStatus WHERE Address = '" & sName & "'")
 For Each oPingResult In cPingResults
  If oPingResult.StatusCode = 0 Then
   TestPing = True
  Else
   TestPing = False
  End If
 Next
End Function



How helpful was this article to you?

Related Articles

article VBScript to Change Admin Password on AD Computers
The password is statically set in the...

(No rating)  5-2-2008    Views: 146   
article Add VBScript to New File Context Menu - Requires Local Admin Rights
  filetype = ".vbs" '...

(No rating)  3-24-2008    Views: 149   
article VBScript to List Network Shares
This script will interrogate the operating...

(No rating)  5-1-2008    Views: 138   

User Comments

Add Comment
No comments have been posted.