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

后端 未结 2 1216
难免孤独
难免孤独 2021-01-19 05:12

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

Working:

Process.Start(new ProcessStartInfo(@\"c:\\Win         


        
2条回答
  •  清酒与你
    2021-01-19 05:47

    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\"";
    

提交回复
热议问题