Page 1 of 1 1
Topic Options
#173661 - 2007-02-05 11:14 PM Delete from groups (local and domain)
DStelz Offline
Getting the hang of it

Registered: 2007-01-26
Posts: 72
Loc: Green Bay, WI
I haven't been able to find anything or I could be just overlooking something, but is there a script or function to remove someone from a group either from the local machine or globally?

Thanks,
-Dave

Top
#173689 - 2007-02-06 10:39 PM Re: Delete from groups (local and domain) [Re: DStelz]
rsifre Offline
Fresh Scripter

Registered: 2007-02-06
Posts: 6
Loc: FL, Pinellas
There is a vbs that will do the trick, I just dont know how to convert it to kix

code:

Set oWshNet = CreateObject("WScript.Network")
sComputer = oWshNet.ComputerName

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


' suppress errors, e.g. trying to remove the builtin Administrator
' account from the Administrators group will fail.
On Error Resume Next

' loop through all members of the Administrators group of type users
For Each oMember In oGroup.Members
If oMember.Class = "User" Then
' remove the user from Administrators group
oGroup.Remove oMember.ADsPath
End If
Next


The script removes users from the local admin group, you can tweak it to remove users from other groups.
_________________________
I am a newbie to kix

Top
#173694 - 2007-02-06 11:20 PM Re: Delete from groups (local and domain) [Re: rsifre]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe something like this (I did not test this)
 Code:
If NOT @LOGONMODE
	Break On
Else
	Break Off
EndIf
Dim $RC
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")

Dim $objWshNet, $strComputer, $objGroup, $objMember

$objWshNet = CreateObject("WScript.Network")
$strComputer = $objWshNet.ComputerName

$strComputer ?

; group to remove user from
$objGroup = GetObject("WinNT://" + $strComputer + "/Administrators")

; Loop through all names of members of group
;For Each $objMember in $objGroup.Members
;	$objMember.Name ?
;Next
;"Error " + @ERROR + " - " + @SERROR ?

; I think There is no KiX code to replace this:
; suppress errors, e.g. trying to remove the builtin Administrator
; account from the Administrators group will fail.
; On Error Resume Next

; loop through all members of the Administrators group of type users
For Each $objMember In $objGroup.Members
	If $objMember.Class = "User"
		; Administrator cannot and should not be removed
		If NOT $objMember.Name = "Administrator"
			; remove the user from Administrators group
			$objGroup.Remove($objMember.ADsPath)
		EndIf
	EndIf
Next

Maybe also look here:
Hey, Scripting Guy! How Can I Compare the Memberships of Two Groups?

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.161 seconds in which 0.137 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org