Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

Rename Local User Script

248 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Dave

ungelesen,
05.05.2003, 14:30:4705.05.03
an
I am looking to write a script that will rename a
specific local user account that has been setup on
several workstations.
I think this may be more WMI than ADSI but I am new to
scripting.
Does anyone know how to do this? I cannot find anything
on the web, everything I have found is for a domain user
account.
Any help is greatly appreciated.
Thanks

Dave

Torgeir Bakken (MVP)

ungelesen,
05.05.2003, 17:58:5105.05.03
an
Dave wrote:

Hi

A tip: There is a better chance to get answers on scripting question in the
group microsoft.public.scripting.wsh

URL to the group for those who uses the not so good Web interface to access the
newsgroups:
http://communities.microsoft.com/Newsgroups/default.asp?ICP=MSCOM&sLCID=US&newsgroup=microsoft.public.scripting.wsh

For ADSI scripting, the group microsoft.public.adsi.general is also a good one.

URL to the group for those who uses the not so good Web interface to access the
newsgroups:
http://communities.microsoft.com/Newsgroups/default.asp?ICP=MSCOM&sLCID=US&newsgroup=microsoft.public.adsi.general

For WinXP, you can use both WMI and ADSI to rename local users (for Win2k, WMI
is not an option). Note that you can do much more with local user accounts
using ADSI than with WMI. Code for both methods below.


=============================================
WMI: Win32_UserAccount.Rename
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/rename_method_in_class_win32_useraccount.asp

' code start

sOldUser = "Administrator"
sNewUser = "RenamedAdmin"

sComputerName = "." ' use "." for local computer

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 below renames local users on a computer (local or remote), using ADSI
from a vbscript.


' code start

sOldUser = "Administrator"
sNewUser = "RenamedAdmin"


sComputerName = "SomeComputer"

' If you want to do this on the local computer, enable the following lines
' to get computer name for local computer
'Set oWshNet = CreateObject("WScript.Network")
'sComputerName = oWshNet.ComputerName

sNewUser = "RenamedAdmin"
sOldUser = "Administrator"

Set oComputer = GetObject("WinNT://" & sComputerName)

' Turn off error handling in case sOldUser does not exist
On Error Resume Next
Set oUser = GetObject("WinNT://" & sComputerName & "/" & sOldUser & ",user")
Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser)
On Error Goto 0

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Dave

ungelesen,
06.05.2003, 05:17:2006.05.03
an
Thanks!!
Tried it and it worked!
This should save us a bundle of time!!

>.
>

0 neue Nachrichten