title: Assistance needed with vbs to change Admin Account
body: <p>I've been tasked with creating a vbs to do the following: 
  If NewAdmin exists then Set password for NewAdmin and disable Local Administrator account 
  Else Rename local Administrator account to NewAdmin and set password.</p>
  
  <p>Thanks again for the quick reply.  I have changed the code below accordingly and am now trying to use the Windows Script Encoder to obfuscate the password.  I understand that there is still a risk involved as this could be decoded, but the script will not be stored on the user's computer and as such will not pose much of a threat.</p>
  
  <p>The code now shows the three added lines needed for the Windows Script Encoder to do it's job, but I can't get it to work.  I run the following command from the command line:</p>
  
  <p>screnc /l vbscript admin_script.vbs admin_script.vbe</p>
  
  <p>It creates the admin_script.vbe successfully.  But then when I attempt to run the encoded script it presents the following error message:</p>
  
  <pre><code>Script:    C:\...\admin_script.vbe
  Line:      2
  Char:      1
  Error:     Expected Statement
  Code:      800A0400
  Source:    Microsoft VBscript compilation error
  </code></pre>
  
  <p>The unencoded script runs without issues.  I have tried another method to encode the data using a vbscript I located online, but it does the same thing ... obfuscates the data but the script doesn't work afterwords.  I also read that it may be an encoding issue and that I needed to save the vbs as UTF-8 without BOM but that didn't work either.  </p>
  
  <p>If anyone knows how to get this Windows Script Encoder working I would greatly appreciate it.  Also, if there is another method for encrypting / obfuscating the code, any suggestions are welcome.  I will say that I'm not a big fan of creating an executable from VBS, but will resort to that if necessary.</p>
  
  <pre><code>&lt;SCRIPT LANGUAGE="VBScript"&gt;
  '**Start Encode**
  OPTION EXPLICIT
  DIM objNetwork, objUser, objComputer
  DIM strPassword, strAdminUserName, strNewAdminUserName, strComputer, strUser
  
  ' Get Computer Name and make it all uppercase
  SET objNetwork = CREATEOBJECT("Wscript.Network")
  strComputer = UCASE(objNetwork.ComputerName)
  ' Setting veriable for IF statement
  strUser= "NewAdmin"
  ' The old name of the administrator user account (normally administrator)
  strAdminUserName = "Administrator"
  ' The new name of the administrator user account
  strNewAdminUserName = "NewAdmin"
  ' New Password for administrator account.
  strPassword = "passwordhere"
  
  On Error Resume Next
  Set objUser = GetObject("WinNT://" &amp; strComputer &amp; "/" &amp; strUser &amp; ",user")
  If (Err.Number = 0) Then
    On Error GoTo 0
      ' Set password of admin user account
      setPWD strComputer,strNewAdminUserName,strPassword
      ' Disable Local Administrator account
      Set objUser = GetObject("WinNT://" &amp; strComputer &amp; "/Administrator, user")
      objUser.AccountDisabled = True
      objUser.SetInfo  
  Else
    On Error GoTo 0
      ' Rename admin user account
      renameUser strComputer,strAdminUserName,strNewAdminUserName
      ' Set password of admin user account
      setPWD strComputer,strNewAdminUserName,strPassword  
  End If
  
  ' enter code hereReset password for a local user account on a given computer
  SUB setPWD(strComputer,strUser,strPassword)
  
      DIM objUser
      ' Ignore error if user account isn't found or error changing password
      ON ERROR RESUME NEXT 
      SET objUser = GETOBJECT("WinNT://" &amp; strComputer &amp; "/" &amp; strUser &amp; ",user")
      IF err.number = 0 THEN
          objUser.SetPassword strPassword
          objUser.SetInfo
      END IF
      ON ERROR GOTO 0
  
  END SUB
  
  ' Rename a local user account on a given computer
  SUB renameUser(strComputer,strFromName, strToName)
  
      DIM objComputer,objUser
      ' Ignore error if user account isn't found or error moving user
      ON ERROR RESUME NEXT
      SET objComputer = GETOBJECT("WinNT://" &amp; strComputer)
      SET objUser = GETOBJECT("WinNT://" &amp; strComputer &amp; "/" &amp; strFromName &amp; ",user")
      IF err.number = 0 THEN
          objComputer.MoveHere objUser.ADsPath,strToName
      END IF
      ON ERROR GOTO 0
  
  END SUB
  &lt;/SCRIPT&gt;
  </code></pre>