![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | renaming Local user account and Changing "Full Name" of same Local 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/ |
My System Specs![]() |
| | #2 (permalink) |
| | Re: renaming Local user account and Changing "Full Name" of same Local "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/ 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 -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| VBScript to Change only "maximum password age" in Local User Accou | VB Script | |||
| How to config "local machine"-->"personal" access right? | Vista General | |||
| What to do to access "Local Settings" and "Application Data"? | Vista account administration | |||
| How to search "globally" under the single title "Local Folders?? | Vista mail | |||
| Public network connection only "Access: Local" & not Local & Inter | Vista networking & sharing | |||