Jump to content

rename local user accounts


Recommended Posts

I know this can be done with GPO's. We do use that method for our desktops, but our SOP requires that we rename the local accounts on servers when we build them.

The VBS code below will do it, but I'd like to conver it to AutoIT as I have a much larger script that configures a lot of other options on the servers. I could use the VB script as an include file, but would prefer to keep it clean with AutoIT.

VBS version

Set oWshNet = CreateObject("WScript.Network")

sComputerName = oWshNet.ComputerName
sOldUser = "Guest"
sNewUser = "Guestuser"
Set oComputer = GetObject("WinNT://" & sComputerName)

' Turn off internal error handling
On Error Resume Next

' connect to user object
Set oUser = GetObject("WinNT://" & sComputerName & "/" & sOldUser & ",user")

' rename user
Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)

I've tried to convert to AutoIT, but get errors on

$oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser)

Error:

E:\Scripting\AutoIT\InProgress\RenameLclAdmin\RnmLclAdmin2.00.au3 (10) : ==> Variable must be of type "Object".: 
$oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser) 
$oNewUser = $oComputer.MoveHere($oUser^ ERROR
+>AutoIT3.exe ended.rc:0

Attempted conversion to AutoIT

$oWshNet = ObjCreate("WScript.Network")
$ComputerName = $oWshNet.ComputerName
$OldUser = "Guest"
$NewUser = "Guestrenamed"
$oUser = ObjGet("WinNT://" & $ComputerName & "/" _
                & $OldUser & ",user")
$oComputer = ObjGet("WinNT://" & $ComputerName)
; rename user
$oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser)

Any suggestions on how to rename the local Guest or Administrator accounts with AutoIT?

Thanks!

Link to comment
Share on other sites

Hello,

Are you trying to compile with the stable version?

I dont' think it supports objects.

Also, you have to create the object. When you get that error, it basically means that the object wasn't declared.

Last, You can use IsObj to do some checking, either for error handling, or how ever you wanna handle it. Its a pretty nice function.

HTH,

~~TheCreator

Link to comment
Share on other sites

  • Developers

Any suggestions on how to rename the local Guest or Administrator accounts with AutoIT?

Thanks!

$OldUser = "Guest"
$NewUser = "Guestrenamed"
$oUser = ObjGet("WinNT://" & @ComputerName & "/" & $OldUser & ",user")
$oComputer = ObjGet("WinNT://" & @ComputerName)
$oNewUser = $oComputer.MoveHere($oUser.ADsPath, $NewUser)

:D

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 4 years later...

Bada Bing!

So easy when you use what AutoIT has to offer. I was going about it the hard way.

Thanks JdeB!!!

So true! Thanks for this example. I was trying to use WMI as the Scripting Guys suggested but couldn't figure it out.

This was another option but not graceful enough for me.

(from http://social.technet.microsoft.com/Forums/en/mdt/thread/edc88cb5-f9b0-4862-adf9-bb2b73940ee7)

wmic useraccount where name='Administrator' call rename name='YourAdminName'

Your example worked, but I had to add an error check in case the old user name didn't exist.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...