Re: script to add a user to the local administrators group
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 01/14/05
- Next message: emebohw2_at_netscape.net: "Re: script to add a user to the local administrators group"
- Previous message: emebohw2_at_netscape.net: "script to add a user to the local administrators group"
- In reply to: emebohw2_at_netscape.net: "script to add a user to the local administrators group"
- Next in thread: emebohw2_at_netscape.net: "Re: script to add a user to the local administrators group"
- Reply: emebohw2_at_netscape.net: "Re: script to add a user to the local administrators group"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 Jan 2005 20:01:27 +0100
emebohw2@netscape.net wrote:
> Can someone post a (complete!) vbscript (wmi, wsh, whatever!) that will
> add a single user to the local administrator group? I have a BAT file
> that does this, but it hangs sometimes for no good reason so I would
> like to try vb.
>
Hi
Adding a local user account to the Administrators group:
'--------------------8<----------------------
' name of user to be added
sUser = "tst"
' name of the group the user is to be added to
sGroupname = "Administrators"
' get computer name
Set oWshNet = CreateObject("WScript.Network")
sComputerName = oWshNet.ComputerName
' connect to the group
Set oGroup = GetObject("WinNT://" & sComputerName & "/" & sGroupname)
' connect to the user
Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser & ",user")
' Add the user to the group
' Use error handling in case the account is a member already
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
'--------------------8<----------------------
Adding a domain user account to the Administrators group:
'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")
sUser = "fill in some domain user name here"
sNetBIOSDomain = oWshNet.UserDomain
sComputer = oWshNet.ComputerName
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group")
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user")
' suppress errors in case the user is already a member
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
'--------------------8<----------------------
If the computers are in another domain than the user you
want to add, you will need to hard code the domain name
the user belongs to in the variable "sNetBIOSDomain".
-- 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/default.mspx
- Next message: emebohw2_at_netscape.net: "Re: script to add a user to the local administrators group"
- Previous message: emebohw2_at_netscape.net: "script to add a user to the local administrators group"
- In reply to: emebohw2_at_netscape.net: "script to add a user to the local administrators group"
- Next in thread: emebohw2_at_netscape.net: "Re: script to add a user to the local administrators group"
- Reply: emebohw2_at_netscape.net: "Re: script to add a user to the local administrators group"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|