Re: Change local Administrator account name?
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 02/14/05
- Next message: Miyahn: "Re: Ordering files by part of the name"
- Previous message: SO: "Change local Administrator account name?"
- In reply to: SO: "Change local Administrator account name?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 12:30:33 +0100
SO wrote:
> Is it possible to change the Administrator account name on a
> remote machine using script?
Hi
The script below should do the job against a remote domain computer
as long as user running the script have administrator rights on it.
If this is for AD domain computers, you could also put it into a
startup script (with a GPO) that runs as part of the boot up process
(before the user logs in). It runs under the system context and has
admin rights.
If you would like to set the password as well, take a look at this
post:
http://groups.google.co.uk/groups?selm=uzxklzP%23EHA.3376%40TK2MSFTNGP12.phx.gbl
'--------------------8<----------------------
'
' Description: Script that renames the builtin administrator
' account to the name set in the variable sNewUser.
'
' Should also work against a remote domain computer as long
' as user running the script have administrator rights on it.
' (you just need to adjust the sComputerName definition)
'
' new user name for the builtin Administrator account
sNewUser = "AdministratorRenamed"
Set oWshNet = CreateObject("WScript.Network")
' get computer name for local computer
sComputerName = oWshNet.ComputerName
' If you want to run the script against a remote computer,
' disable the line above and enable the line below
'sComputerName = "SomeComputer"
' obtain current administrator name regardless of old name
sOldUser = GetAdministratorName(sComputerName)
' Turn off internal error handling
On Error Resume Next
' connect to user object
Set oUser = GetObject("WinNT://" & sComputerName & "/" _
& sOldUser & ",user")
If LCase(sNewUser) <> LCase(sOldUser) Then
Set oComputer = GetObject("WinNT://" & sComputerName)
' rename user
Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)
End If
On Error Goto 0
Function GetAdministratorName(sComputerName)
Dim sUserSID, oWshNetwork, oUserAccount
Set oUserAccounts = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!//" _
& sComputerName & "/root/cimv2").ExecQuery( _
"Select Name, SID from Win32_UserAccount WHERE Domain = '" _
& sComputerName & "'")
On Error Resume Next
For Each oUserAccount In oUserAccounts
If Left(oUserAccount.SID, 9) = "S-1-5-21-" And _
Right(oUserAccount.SID, 4) = "-500" Then
GetAdministratorName = oUserAccount.Name
Exit For
End if
Next
End Function
'--------------------8<----------------------
-- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/scriptcenter/default.mspx
- Next message: Miyahn: "Re: Ordering files by part of the name"
- Previous message: SO: "Change local Administrator account name?"
- In reply to: SO: "Change local Administrator account name?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|