Re: Adding a domain user to the local Administrators Group

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 07/07/04


Date: Wed, 07 Jul 2004 19:18:25 +0200

Mike A. wrote:
> Does anyone know if there is a way to add a domain user to the local
> Administrators group using a script? The following script works if the user
> is a local user.
>
> strComputer = "MyComputer"
> Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
> Set objUser = GetObject("WinNT://" & strComputer & "/mike,user")
> objGroup.Add(objUser.ADsPath)
>
> Any help on this would be greatly appreciated.
Hi

Set objWshNet = CreateObject("WScript.Network")
strComputer = objWshNet.ComputerName
' hard code domain name here if necessary:
strNetBIOSDomain = objWshNet.UserDomain

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strNetBIOSDomain & "/mike,user")

On Error Resume Next ' suppress error in case user is already a member
objGroup.Add(objUser.ADsPath)
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/community/scriptcenter/default.mspx


Relevant Pages

  • Re: Remove Users From Local Admin Group
    ... > local Admin group from the login script. ... Both local and domain users will be removed ... ' account from the Administrators group will fail. ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.scripting.vbscript)
  • Re: Adding a domain user to the local Administrators Group
    ... > Mike A. wrote: ... >> Administrators group using a script? ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)
  • Re: Workaround for 0x8007045A (!)
    ... >> add to the Administrators group), you need to select the local computer ... > domain user that prevents WU5 from operating correctly. ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windowsupdate)
  • Re: Script for creating a new user
    ... I want to create a local user. ... Creating a local user and adding it to the Administrators group ... ' Use error handling in case the account is a member already ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)
  • Re: AD in Local Groups differente languajes?
    ... > the local Administrators group on every workstation, ... > have different languages on the workstation and the Administrators group ... To run this WMI query against NT4 computers, ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.windows.server.scripting)