Real Geek Forums  

Go Back   Real Geek Forums > Archives > Operating Systems > Windows XP > Windows XP Configuration & Management

Notices

Reply

Add Domain user to Local Group via vb script

 

LinkBack Thread Tools Display Modes
Old 09-01-2004, 06:09 PM   #1 (permalink)
Default Add Domain user to Local Group via vb script

I am looking to add a domain user to the local admin group
via vb scripting. I have a script to add a local user to
the local group but am uncertain how to modify
appropriately to pull the domain user.

Any help?
Jason
Guest
 
Posts: n/a
Reply With Quote  
Old 09-01-2004, 06:40 PM   #2 (permalink)
Default Re: Add Domain user to Local Group via vb script

Jason wrote:
Quote:
> I am looking to add a domain user to the local admin group
> via vb scripting. I have a script to add a local user to
> the local group but am uncertain how to modify
> appropriately to pull the domain user.
>
> Any help?
Hi


'--------------------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/scr...r/default.mspx
Torgeir Bakken \(MVP\)
Guest
 
Posts: n/a
Reply With Quote  
Old 09-01-2004, 06:55 PM   #3 (permalink)
Default Re: Add Domain user to Local Group via vb script

To take this one step further, the DOMAIN USERS group had
been added to the Local Admin group. How can I, via
vbscript, remove that group from the workstations?

Thanks,
Quote:
>-----Original Message-----
>Jason wrote:
>
Quote:
>> I am looking to add a domain user to the local admin
group
Quote:
Quote:
>> via vb scripting. I have a script to add a local user
to
Quote:
Quote:
>> the local group but am uncertain how to modify
>> appropriately to pull the domain user.
>>
>> Any help?
>Hi
>
>
>'--------------------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")
Quote:
>Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" &
sUser & ",user")
Quote:
>
>' 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/scr...r/default.mspx
>.
>
Guest
 
Posts: n/a
Reply With Quote  
Old 09-01-2004, 07:22 PM   #4 (permalink)
Default Re: Add Domain user to Local Group via vb script

anonymous@discussions.microsoft.com wrote:
Quote:
> To take this one step further, the DOMAIN USERS group had
> been added to the Local Admin group. How can I, via
> vbscript, remove that group from the workstations?
Hi


'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")

' computer name
sNode = oWshNet.ComputerName

' group name to remove user or group from
Set oGroup = GetObject("WinNT://" & sNode & "/Administrators")

' loop through all member of the group
For Each oUser In oGroup.Members

' get the name and make it lowercase
sGroupEntry = LCase(oUser.Name)

If (sGroupEntry = "domain users") Then
' remove entry from group
oGroup.Remove oUser.ADsPath
End if
Next
'--------------------8<----------------------


--
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/scr...r/default.mspx
Torgeir Bakken \(MVP\)
Guest
 
Posts: n/a
Reply With Quote  
Old 09-01-2004, 07:39 PM   #5 (permalink)
Default Re: Add Domain user to Local Group via vb script

Thanks Much.

These scripts really help.
Quote:
>-----Original Message-----
>anonymous@discussions.microsoft.com wrote:
>
Quote:
>> To take this one step further, the DOMAIN USERS group
had
Quote:
Quote:
>> been added to the Local Admin group. How can I, via
>> vbscript, remove that group from the workstations?
>Hi
>
>
>'--------------------8<----------------------
>Set oWshNet = CreateObject("WScript.Network")
>
>' computer name
>sNode = oWshNet.ComputerName
>
>' group name to remove user or group from
>Set oGroup = GetObject("WinNT://" & sNode
& "/Administrators")
Quote:
>
>' loop through all member of the group
>For Each oUser In oGroup.Members
>
> ' get the name and make it lowercase
> sGroupEntry = LCase(oUser.Name)
>
> If (sGroupEntry = "domain users") Then
> ' remove entry from group
> oGroup.Remove oUser.ADsPath
> End if
>Next
>'--------------------8<----------------------
>
>
>--
>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/scr...r/default.mspx
>.
>
Jason
Guest
 
Posts: n/a
Reply With Quote  
Old 09-05-2004, 09:06 PM   #6 (permalink)
Default Re: Add Domain user to Local Group via vb script

You can also do this pretty easily via the "net localgroup" command (though
this isn't really VBScript, you could call it from a vbs):

net localgroup Administrators /add DOMAIN\USERNAME

--
Please reply in newsgroup.

This posting is provided "AS IS" with no warranties, and confers no rights.



"Jason" <jason.brimhall@questar.com> wrote in message
news:015a01c4904e$c8fa1d20$a401280a@phx.gbl...
Quote:
>I am looking to add a domain user to the local admin group
> via vb scripting. I have a script to add a local user to
> the local group but am uncertain how to modify
> appropriately to pull the domain user.
>
> Any help?

Delwin Lee [MSFT]
Guest
 
Posts: n/a
Reply With Quote  
Reply

Tags
None

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
remotely query group membership of machine via script/wmi sumGirl Windows XP WMI 3 11-30-2004 01:40 PM
programs installled either as local/network admin will not run as domain user brenden Windows XP Configuration & Management 0 08-27-2004 10:54 AM
Standard user (power user group) Ray Windows XP Configuration & Management 1 07-31-2004 07:08 PM
Make local computer user domain user too? Ken Very Big Liar Windows XP Help & Support 1 10-02-2003 02:16 AM
Creating a Logon Script for a local user Neil Windows XP New Users 0 07-15-2003 07:47 PM


All times are GMT. The time now is 05:54 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright © 2005 - 2007 RealGeek.com. All rights reserved.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90