0

I have the following C# code that runs a command line:

ProcessStartInfo si = new ProcessStartInfo();
si.FileName = @"Lib\my_program.exe";

si.WindowStyle = ProcessWindowStyle.Hidden;
si.UseShellExecute = false;
si.CreateNoWindow = true;

si.Arguments = "my args";

Process p = new Process();
p.StartInfo = si;
p.Start();

It works perfect on one computer, but when running it on different computer - nothing happens.

When trying to run it via the command line at the problematic computer - it also works fine.

all the paths are correct and I run it with an admin permission.

What can go wrong? maybe some environment variables? or computer's security issues?

3
  • 3
    Are you sure the current directory is set right? Try creating a FileInfo object on the exe path and ask if it exists. Commented Dec 20, 2013 at 12:28
  • Are you sure 2nd computer has the same framework version or upper? Commented Dec 20, 2013 at 13:32
  • You stay out of trouble by always specifying the full path (like c:\foo\bar\baz.exe) and always setting the ProcessStartInfo.WorkingDirectory property. Use the Assembly.GetEntryAssembly().Location property to build the path. Commented Dec 20, 2013 at 14:13

2 Answers 2

1

As it works when running from the command line, I would say that your application shortcut is running the program with a different working directory (so the relative path Lib\my_program.exe doesn't resolve to an existing program).

More generally, Process.Start() can throw various exceptions (probably FileNotFoundException in this case) so I suggest you wrap the code with a try/catch block and write the exception to Console.Error or display an error dialog.

Sign up to request clarification or add additional context in comments.

1 Comment

Definitely put in a try/catch because this will more than likely answer your question on its own.
0

Check here ProcessStartInfo.EnvironmentVariable["Path"] . If this doesn't have the "my_program.exe"'s parent folder. Then probably it is not knowing the location. Remember, here "Path" is case sensitive. Thanks go to my senior who cleared my doubt today on this one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.