Jump to content

How to rename an user correctly in autoit?


Payback
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • 1 month later...
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/

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

  • 3 weeks later...

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...