I am creating a UI for our IT Department that shadow a user's session. First, you have to get the session ID using the following command.
Process Process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe", "/K" + "qwinsta /server:" + ComputerName + " " + Username);
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
Process = Process.Start(startInfo);
And this is what you get out.
SESSIONNAME USERNAME ID STATE TYPE DEVICE
console mlynch 8 Active
As of right now, this opens the command prompt for this command with the computer name and username you put into a couple of text boxes. You then take the session ID and input it into a 3rd text box and click the connect button. I am trying to bypass this step. Input the computer and username, click connect and it goes. I need to find a way to get the session ID and save it to a string, then reference that string in the next line of code.
if (MouseControlCheck.Checked == true)
{
Process Process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe", "/C" + "mstsc.exe /shadow:" + SessionID + " /v " + ComputerName + " /control");
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
Process = Process.Start(startInfo);
}
else
{
Process Process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe", "/C" + "mstsc.exe /shadow:" + SessionID + " /v " + ComputerName);
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
Process = Process.Start(startInfo);
}
How do I read the session ID to a string?
TLDR: I want to skip over console and mlynch and just get to the number under ID. This is not going to be used to get the local machine ID, I want the ID of a computer on the network.