Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - renaming Local user account and Changing "Full Name" of same Local

Reply
 
Old 11-20-2008   #1 (permalink)
HCSOIT


 
 

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 SpecsSystem Spec
Old 11-20-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

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


My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46