private void SwitchDesktops() { AditClient.DesktopSwitchPending = true; Utilities.WriteToLog($"Desktop switch initiated to {desktopName}."); var procInfo = new ADVAPI32.PROCESS_INFORMATION(); var sessionID = Guid.NewGuid().ToString(); if (ADVAPI32.OpenInteractiveProcess(Path.Combine(Utilities.ProgramFolder, "Adit.exe") + $" -upgrade {AditClient.SessionID}", desktopName, out procInfo)) { AditClient.SocketMessageHandler.SendDesktopSwitch(); return; } else { var error = Marshal.GetLastWin32Error(); if (error == 6) { Utilities.WriteToLog("Desktop switch failed during a Windows session change."); } else { Utilities.WriteToLog(new Exception("Failed to switch desktops. Error: " + error.ToString())); } return; } }
private void ReceiveRequestForElevatedClient(dynamic jsonData) { var sessionID = Guid.NewGuid().ToString(); var desktopName = User32.GetCurrentDesktop(); var procInfo = new ADVAPI32.PROCESS_INFORMATION(); var processResult = ADVAPI32.OpenInteractiveProcess(Path.Combine(Utilities.ProgramFolder, "Adit.exe") + $" -upgrade {sessionID}", desktopName, out procInfo); if (processResult == false) { jsonData["Status"] = "failed"; SendJSON(jsonData); Utilities.WriteToLog(new Exception("Error opening interactive process. Error Code: " + Marshal.GetLastWin32Error().ToString())); } else { jsonData["Status"] = "ok"; jsonData["ClientSessionID"] = sessionID; SendJSON(jsonData); } }