Looks like it’s not.
If I convert the file name to its short value, then Process.Start() works.
Process runScripts = new Process(); runScripts.StartInfo.FileName = @'C:\long file path\run.cmd'; runScripts.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; runScripts.StartInfo.UseShellExecute = true; runScripts.StartInfo.RedirectStandardOutput = false; runScripts.Start();
The above code fails. But…
Process runScripts = new Process(); runScripts.StartInfo.FileName = @'C:\short\file\path\run.cmd'; runScripts.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; runScripts.StartInfo.UseShellExecute = true; runScripts.StartInfo.RedirectStandardOutput = false; runScripts.Start();
succeeds.
I managed to get around this by converting the long path name to a short path name. But I am a bit surprised to find this. Any reasons or background info on this?
Thanks.
Update 1
Microsoft .NET Framework Version 2.0.50727
To reproduce your problem, I used the following program:
The code starts a new process (as per your code sample) and reports the different ways in which it may fail to execute. You can compile the program from command line:
(assuming test.cs is in the current directory; it will create test.exe in the same directory as test.cs)
As expected, when ‘C:\long file path\run.cmd’ does not exist, the program fails with:
Now let’s create a directory ‘C:\long file path’ and put a very simple run.cmd in there:
However, at this point I was unable to reproduce your failure. Once the above run.cmd is in place, test.exe runs successfully (i.e. run.cmd is executed correctly – you can verify this by looking for a newly created file ‘C:\long file path\run.out.txt’.
I ran test.exe on Vista x64 (my main dev machine), Windows XP SP3 x86 (virtual machine), Windows Server 2008 x64 (virtual machine) and it works everywhere.
Could you try running the above code in your environment and report back whether it is failing for you? This way we will at least establish the same testing context (same .NET program will be trying to run the same batch file in the same location for you as it does for me).