N
N
NameOf Var2018-03-16 19:28:08
.NET
NameOf Var, 2018-03-16 19:28:08

How to fix PsExec launch issue in C#?

You need to remotely install the MSI package using the PsExec utility. All this must be done through a C# console application. Here is my solution:

src
string psExecPath = @"C:\Program Files\Utility\64\PsExec.exe";
            string arg = String.Join(" ", args);

            var process = new Process()
            {
                StartInfo = new ProcessStartInfo(psExecPath, arg)
                {
                    RedirectStandardError = true,
                    UseShellExecute = false,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    CreateNoWindow = true
                }
            };

            Console.WriteLine("Starting process...");

            process.Start();
            process.WaitForExit(60000);

            if (!process.HasExited)
            {
                process.Kill();
                Console.WriteLine("Wait for exit: Time out");
                return;
            }

            if (process.ExitCode != 0)
                Console.WriteLine($"Error occurred during the execution PsExec. ErrorCode {process.ExitCode}");


The args string contains the following arguments: \\MACHINE-64 -u "INT\Administrator" -p "qwerty" msiexec /i "C:\Users\MyUser\Desktop\temp\Installer.msi" /
qn regular cmd with the given arguments, the installer successfully works and installs on the remote machine. But if I run PsExec with arguments through my console application, then PsExec just hangs in the processes and nothing happens.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question