<WebMethod()> _ Function RemoveFromGroup(ByVal target_group As String, ByVal domain As String, ByVal account As String, ByVal system As String) As Object '############################# 'Function RemoveFromGroup 'Variables 'system Target server 'domain of Group / User being added 'account (Name of Group or User) 'target_group group we are modifying membership 'Returns 'STATUS|domain:account|TIMESTAMP as a single string Dim AlreadyExists As Integer Dim action = "RemoveFromGroup" 'Create an group object referencing the group on the target server objLocalGroup = GetObject("WinNT://" & system & "/" & target_group & ",group") If Err.Number = 0 Then 'Check to see if the account already exists in the local Admin group For Each Group In objLocalGroup.Members If InStr(UCase(Group.ADSPath), UCase(domain & "/" & account)) <> 0 Then AlreadyExists = True End If Next 'Add the specified account to the local target group if it doesn't already exist If AlreadyExists = True Then objLocalGroup.Remove("WinNT://" & domain & "/" & account) If Err.Number = 0 Then RemoveAccountFromLocalGroup = 0 Else RemoveAccountFromLocalGroup = 1 Err.Clear() End If Else RemoveAccountFromLocalGroup = 2 End If Else RemoveAccountFromLocalGroup = 3 retmsg = "FAILED-cannot connect to server|" & action & "|" & domain & ":" & account & "|" & Date.Now & "|group-" & target_group Err.Clear() End If If RemoveAccountFromLocalGroup = 0 Then retmsg = "SUCCESS|" & action & "|" & domain & ":" & account & "|" & Date.Now & "|group-" & target_group ElseIf RemoveAccountFromLocalGroup = 1 Then retmsg = "FAILED|" & action & "|" & domain & ":" & account & "|" & Date.Now & "|group-" & target_group ElseIf RemoveAccountFromLocalGroup = 2 Then retmsg = "SUCCESS-NA|" & action & "|" & domain & ":" & account & "|" & Date.Now & "|group-" & target_group End If 'clear variables to prevent memory leaks strDomainUser = Nothing objDomainUser = Nothing objLocalGroup = Nothing AlreadyExists = Nothing RemoveAccountFromLocalGroup = Nothing action = Nothing Return retmsg End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)