Problem with Process

B

Bala Nagarajan

Hello,
I am having issues when i use the Systsem.Diagnostics.Process
namespace to start a process. The problem is that i am able to succeed in
starting a process (an exe) only few times in a row from a windows
application before it fails throwing the following exception. (The exe i am
trying to run is in the same directory as the application.)

System.ComponentModel.Win32Exception
The system cannot find the file specified
System.ComponentModel.Win32Exception: The system cannot find the file
specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo)
at System.Diagnostics.Process.Start()

I have no idea why it would succeed the first few times and fail then. I am
posting the code i am am using.

System.Diagnostics.Process normComm = new System.Diagnostics.Process();
string pathEXE = "myprog.exe";
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo(Environment.CurrentDirectory + @"\" +
pathEXE);
string args = "argument";
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.Arguments = args;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;

normComm.StartInfo = startInfo;
try
{
normComm.Start(); //exception here

}

Any thoughts???Any help will be greatly appaerciated as i am unable to get a
breakthrough on this issue.

Thanks
Bala
 
S

SP

Bala Nagarajan said:
Hello,
I am having issues when i use the Systsem.Diagnostics.Process
namespace to start a process. The problem is that i am able to succeed in
starting a process (an exe) only few times in a row from a windows
application before it fails throwing the following exception. (The exe i
am trying to run is in the same directory as the application.)

System.ComponentModel.Win32Exception
The system cannot find the file specified
System.ComponentModel.Win32Exception: The system cannot find the file
specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo
startInfo)
at System.Diagnostics.Process.Start()

I have no idea why it would succeed the first few times and fail then. I
am posting the code i am am using.

System.Diagnostics.Process normComm = new System.Diagnostics.Process();
string pathEXE = "myprog.exe";
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo(Environment.CurrentDirectory + @"\" +
pathEXE);
string args = "argument";
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.Arguments = args;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;

normComm.StartInfo = startInfo;
try
{
normComm.Start(); //exception here

}

Any thoughts???Any help will be greatly appaerciated as i am unable to get
a breakthrough on this issue.

Perhaps current directory has changed. I believe that some of the dialog
boxes like open file change this and you can change it yourself as well. Use
Path.GetDirectoryName(Application.ExecutablePath) instead.

SP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top