public static logoffReturn LogoffRDPSession(string ComputerName, string SessionID) { string LogoffExe = getLogoffExePath(); if (LogoffExe != null) { ProcessStartInfo psi = new ProcessStartInfo(LogoffExe); psi.Arguments = SessionID + " /SERVER:" + ComputerName; psi.UseShellExecute = false; psi.CreateNoWindow = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; Process LogoffProcess = new Process(); LogoffProcess.StartInfo = psi; bool ProcessStarted = LogoffProcess.Start(); if (ProcessStarted) { LogoffProcess.WaitForExit(); } logoffReturn Results = new logoffReturn(); Results.ExitCode = LogoffProcess.ExitCode; Results.StdOut = LogoffProcess.StandardOutput.ReadToEnd(); Results.StdErr = LogoffProcess.StandardError.ReadToEnd(); return(Results); } else { return(null); } }
// Wird vom Command Binding aufgerufen. parameter enthält das mit "CommandParameter" übergebene Objekt public void Execute(object parameter) { RemoteSession TypedParameter = parameter as RemoteSession; logoffReturn results = functions.LogoffRDPSession(TypedParameter.ServerName, TypedParameter.SessionID); if (results.ExitCode != 0) { LogoffError ErrorWindow = new LogoffError(results); // Make sure the ErrorWindow pops up on the same monitor, // without this it's always the primary (I think) ErrorWindow.Top = Application.Current.MainWindow.Top + 20; ErrorWindow.Left = Application.Current.MainWindow.Left + 20; ErrorWindow.Show(); } }
public LogoffError(logoffReturn LogoffErrorDetails) { InitializeComponent(); this.DataContext = LogoffErrorDetails; }