"HCSOIT" <HCSOIT@xxxxxx> wrote in message
news:B365A29D-7A1D-4490-9C56-307FF8B3E54E@xxxxxx
Quote:
>I have the following code snipet that does a good job of renaming a local
> user account on a computer.
>
> sOldUser = "Agency_user"
> sNewUser = "12LEPATTEST"
>
> strComputer = "."
>
> Set colUsers = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2").ExecQuery _
> ("select Name from Win32_UserAccount where name = '" & sOldUser & _
> "'")
> For Each objAccount in colAccounts objAccount.FullName = "NewAdmin"
> objAccount.Rename sNewUser
>
> If colUsers.Count > 0 Then
> For Each oUser In colUsers
> iRC = oUser.Rename(sNewUser)
> If iRC = 0 Then
> WScript.Echo "User renamed"
> Else
> WScript.Echo "Rename method returned ERROR # " & iRC
> End If
> Next
> Else
> WScript.Echo "No user found"
> End If
>
> I also need to change the "Full Name" of the same account. I have not been
> able to find how to do that. Can some one help me/
You need to bind to the user object and assign a value to the FullName
attribute. The Win32_UserAccount class exposes the FullName attribute, and
it is documented as read/write, but I am unable to use the Win32_UserAccount
class to assign a new value. I would suggest you use the WinNT provider to
bind to the newly renamed user object and assign a new value to FullName.
Perhaps:
========
sOldUser = "Agency_user"
sNewUser = "12LEPATTEST"
strComputer = "."
Set colUsers = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2").ExecQuery _
("select * from Win32_UserAccount where name = '" & sOldUser & _
"'")
For Each objUser In colUsers
objUser.Rename(sNewUser)
Next
Set objUser = GetObject("WinNT://" & strComputer & "/" & sNewUser & ",user")
objUser.FullName = "NewAdmin"
objUser.SetInfo
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--