Search code examples
windowspasswordsadministratorsid

Reset password for renamed Administrator account


I need to create a .VBS script to reset the Windows local administrator password on a large group of computers. My problem is that some of our sites have renamed the administrator account for security reasons. Does anyone have a script which changes the password of the administrator account based on the SID of the original Administrator account?


Solution

  • Using the fact that local admin's SID always ends with -500:

    strComputer="."    ' local computer by default   
    Set objUser=GetObject("WinNT://" & strComputer & "/" & GetAdminName & ",user")     
    objUser.SetPassword "New local admin password"     
    objUser.SetInfo 
    
    Function GetAdminName   
      'This function was written using information from Table J.1 from the Windows XP resource Kit
      'http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prnc_sid_cids.asp
    
      Set objNetwork = CreateObject("Wscript.Network") 'get the current computer name 
      objComputerName = objNetwork.ComputerName    
      Set objwmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & objComputerName)
    
      qry = "SELECT * FROM Win32_Account where Domain = '" & cstr(objComputerName) & "'" 
      'set query, making sure to only look at local computer
    
      For Each Admin in objwmi.ExecQuery(qry)   
        if (left(admin.sid, 6) = "S-1-5-" and right(admin.sid,4) = "-500") then 'look for admin sid
           GetAdminName = admin.name
        end if   
      next    
    end Function