Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The system cannot find the file specified Exception in Process Start (tscon.exe)

Tags:

c#

process

I am getting "The system cannot find the file specified Exception" in Process.Start on tscon

Working:

Process.Start(new ProcessStartInfo(@"c:\Windows\System32\notepad.exe", "temp.txt"));

Not Working:

Process.Start(new ProcessStartInfo(@"c:\Windows\System32\tscon.exe", @"0 /dest:console"));

I need the tscon.exe. why am i getting this error?

EDIT:

  1. Verified that tscon.exe is indeed in c:\Windows\System32 folder.
  2. I am running VS in administrator mode

is there some hardening on that file? not being able to understand this...

like image 749
user829174 Avatar asked Jan 16 '23 11:01

user829174


1 Answers

Oh well, this thing has really got my attention.
I have finally managed to start the tscon.exe from Process.Start.
You need to pass your "admin" account info, otherwise you get the 'File not found' error.

Do in this way

ProcessStartInfo pi = new ProcessStartInfo();
pi.WorkingDirectory = @"C:\windows\System32"; //Not really needed
pi.FileName = "tscon.exe";
pi.Arguments = "0 /dest:console";
pi.UserName = "steve";
System.Security.SecureString s = new System.Security.SecureString();
s.AppendChar('y');
s.AppendChar('o');
s.AppendChar('u');
s.AppendChar('r');
s.AppendChar('p');
s.AppendChar('a');
s.AppendChar('s');
s.AppendChar('s');
pi.Password = s;
pi.UseShellExecute = false; 
Process.Start(pi);

also to see the result of the command change the following two lines

pi.FileName = "cmd.exe";
pi.Arguments = "/k \"tscon.exe 0 /dest:console\"";
like image 105
Steve Avatar answered Feb 05 '23 18:02

Steve