Jump to content

Recommended Posts

Posted

I'm trying to rename an user account in Autoit.

In normal situations, it would work with this code:

 

#NoTrayIcon
#RequireAdmin
$UserName = @UserName
$Password = 'idk'
$strComputer = @ComputerName
$NewUser = "someuser"
;Create UserID
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objUser = $colAccounts.Create("user", $UserName)
$objUser.SetPassword ($Password)
$objUser.Put ("Fullname", $NewUser)
$oComputer = ObjGet("WinNT://" & @ComputerName)
$oNewUser = $oComputer.MoveHere($objUser.ADsPath, $NewUser)
$objUser.SetInfo

But when the user was renamed from the control panel, it changes the ADsPath correctly as you can see in the image I posted:Capture.PNG.b9d9ba5961d03497d3b89a91c17ff3f7.PNG But the user name in the logonui and the user account object in the image still stays at the old user name (usrname) for whatever reason. Could someone help me fix this problem?

  • 1 month later...
Posted
On 10/28/2021 at 1:33 AM, Payback said:

I'm trying to rename an user account in Autoit.

In normal situations, it would work with this code:

 

#NoTrayIcon
#RequireAdmin
$UserName = @UserName
$Password = 'idk'
$strComputer = @ComputerName
$NewUser = "someuser"
;Create UserID
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objUser = $colAccounts.Create("user", $UserName)
$objUser.SetPassword ($Password)
$objUser.Put ("Fullname", $NewUser)
$oComputer = ObjGet("WinNT://" & @ComputerName)
$oNewUser = $oComputer.MoveHere($objUser.ADsPath, $NewUser)
$objUser.SetInfo

But when the user was renamed from the control panel, it changes the ADsPath correctly as you can see in the image I posted:Capture.PNG.b9d9ba5961d03497d3b89a91c17ff3f7.PNG But the user name in the logonui and the user account object in the image still stays at the old user name (usrname) for whatever reason. Could someone help me fix this problem?

https://www.autoitscript.com/forum/topic/29055-rename-local-user-accounts/

none

  • 3 weeks later...
Posted

Did you use the method in the link posted by ad777, or another method?  It may be helpful to future scripters with the same need to know how you solved it.

  • 3 weeks later...
Posted

Hello, spudw2k, i just used another method that involves changing a little bit my code (reconfigure the com objects in my code) and it worked.

 

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
  • Recently Browsing   0 members

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