Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Script to rename local account something else

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,48230
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script to rename local account something else
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Script to rename local account something else - 6/12/2007 8:36:51 PM   
  defisit

 

Posts: 1
Score: 0
Joined: 6/12/2007
Status: offline
Hi,

I currently have a vb script that renames the local guest account on a microsoft server system to guest_%computername%. The problem is that the script does not rename the guest account to guest_<actualcomputername> but to guest_%computername%. I would like to have a script that puts in the actual computername in stead of static value like it does now.

The sript is written out here

-----=====CUT HERE=====>
sComputerName = "." ' use "." for local computer

Set objNet = CreateObject("WScript.NetWork")

Dim sOldUser
Dim sNewUser

sOldUser = "GUEST_%COMPUTERNAME%"
sNewUser = "GUEST_" & objNet.ComputerName


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 sOldUser & " renamed to " & sNewUser
   End if
Next
Else
WScript.Echo "No user found"
End If

-----=====UNCUT HERE===<

Please help
 
 
Post #: 1
 
 RE: Script to rename local account something else - 6/12/2007 8:46:14 PM   
  ginolard


Posts: 1053
Score: 21
Joined: 8/10/2005
Status: offline
Why do you do this?



      

When you could just do this


      

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to defisit)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script to rename local account something else Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts