C# Process Start Stuck

I wrote a simple TCP Server application, when the program gets the request it will call an exe file to do something. The application works fine on my PC.

But when I run on another PC the thread will stuck because it stuck in process start, so I checked the task manager whether the exe file did run. and it really work.

I have no idea how to solve it.

Here is my code:

System.Diagnostics.Process process = new System.Diagnostics.Process();
string path = System.Environment.CurrentDirectory;
process.StartInfo.WorkingDirectory = path;
process.StartInfo.FileName = "FileTransferTool\\FileTransfer.exe";
process.StartInfo.Arguments = argument;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.CreateNoWindow = false;

process.Start();  // the thread stuck here

I print out the message, it shows

System.ComponentModel.Win32Exception (0x80004005):

The system cannot find the file specified at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startIn fo) at System.Diagnostics.Process.Start() at ClassPackage.DsUploadFiletoNC.Start(Object[] param)

1 answer

  • answered 2018-04-17 05:13 Bing Feng

    I have solved this problem by adding another process to call cmd.exe on the top of the main program, the code shown as below :

    And the program will run as Administrator, but I don't know why

    static void Main(string[] args)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            string path = System.Environment.CurrentDirectory;
            process.StartInfo.WorkingDirectory = @"C:\Windows\System32";
    
            process.StartInfo.FileName = "cmd.exe";
            //process.StartInfo.FileName = "FileTransferTool\\circle.txt";
    
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardInput = true;
            //process.StartInfo.CreateNoWindow = false;
            process.Start();
    
            using (TCPServer server = new TCPServer())
            {
                server.Start();
                Console.WriteLine("Socket Server Start...");
                Console.ReadKey(true);
            }
        }