Dave
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
>.
>