<DllImport("user32.dll")> _
Public Shared Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
End Function
Private Shared Sub AddUserToGroup(userDn As String, groupDn As String)
Dim exitCode As Integer = StartBackgroundProcess("dsmod", String.Format("group ""{0}"" -addmbr ""{1}""", groupDn, userDn))
If exitCode <> 0 Then
Console.WriteLine("Could not remove user {0} from group {1}", userDn, groupDn)
End If
End Sub
Private Shared Sub RemoveUserFromGroup(userDn As String, groupDn As String)
Dim exitCode As Integer = StartBackgroundProcess("dsmod", String.Format("group ""{0}"" -rmmbr ""{1}""", groupDn, userDn))
If exitCode <> 0 Then
Console.WriteLine("Could not remove user {0} from group {1}", userDn, groupDn)
End If
End Sub
Private Shared Function StartBackgroundProcess(procPath As String, cmdLine As String) As Integer
Dim psi As New ProcessStartInfo(procPath, cmdLine)
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.CreateNoWindow = True
psi.UseShellExecute = False
Dim proc As Process = Process.Start(psi)
ShowWindow(proc.MainWindowHandle, 0)
proc.WaitForExit()
Return proc.ExitCode
End Function
|