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 - Editing Full Name of a local user

Reply
 
Old 10-09-2008   #1 (permalink)
valerioweb


 
 

Editing Full Name of a local user

Hi guys!
I need to rename an administrator local user and reset the full name
of this.

For rename, I use this script:

-----------SCRIPT START--------------------

' code start

sOldUser = "OldAdmin"
sNewUser = "NewAdmin"

sComputerName = "PC0001"

Set colUsers = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& sComputerName & "\root\cimv2").ExecQuery _
("select Name from Win32_UserAccount where name = '" & sOldUser &
"'")

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

-----------SCRIPT END--------------------

But how I can do to reset the full name of user "NewAdmin" ??
How I can modify my script?

Thanks,
Valerio

My System SpecsSystem Spec
Old 10-09-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Editing Full Name of a local user


<valerioweb@xxxxxx> wrote in message
news:97355677-1626-424b-bb3f-8d3805e7dd71@xxxxxx
Quote:

> Hi guys!
> I need to rename an administrator local user and reset the full name
> of this.
>
> For rename, I use this script:
>
> -----------SCRIPT START--------------------
>
> ' code start
>
> sOldUser = "OldAdmin"
> sNewUser = "NewAdmin"
>
> sComputerName = "PC0001"
>
> Set colUsers = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & sComputerName & "\root\cimv2").ExecQuery _
> ("select Name from Win32_UserAccount where name = '" & sOldUser &
> "'")
>
> 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
>
> -----------SCRIPT END--------------------
>
> But how I can do to reset the full name of user "NewAdmin" ??
> How I can modify my script?
>
> Thanks,
> Valerio
Assign a value to the FullName attribute of the user object. This attribute
is exposed by the Win32_UserAccount class. Also, the following link suggests
a slightly different query.
http://www.microsoft.com/technet/scr...6/hey0517.mspx
I would suggest:============strComputer = "MyComputer"

Set objWMIService = GetObject("winmgmts:" _ &
"{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _ &
strComputer & "\root\cimv2")
Set colAccounts = objWMIService.ExecQuery _
("Select * From Win32_UserAccount Where LocalAccount = True And Name =
'" & sOldUser & "'")

For Each objAccount in colAccounts objAccount.FullName = "NewAdmin"
objAccount.Rename sNewUser
Next==========I don't find documentation for a SetInfo method, so apparently
that is not required by the Win32_UserAccount class of WMI.
-- Richard MuellerMVP Directory ServicesHilltop Lab -
http://www.rlmueller.net--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
The disappearance of local disk (D:) after full system recovery in Vista Home Premium Vista file management
renaming Local user account and Changing "Full Name" of same Local VB Script
Full Local Access for Domain Admins Network & Sharing
local user PowerShell
local user please PowerShell


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