Running a batch file c# throwing error

S

shantanu

Hi all
i am trying to imolement a code to run a batch file. But its throwing
error

"No application is associated with the specified file for this
operation"

The code which i am implementing is

private void InstallDefectService()
{
try
{

string strFilePath = @"C:\Program Files\adi
\DefectTrackingCOMAddinSetup\InstallService.bat";

System.Diagnostics.Process ProcService = new
System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo procInfo = new
System.Diagnostics.ProcessStartInfo();

procInfo.UseShellExecute = true;

procInfo.FileName = strFilePath;


ProcService = System.Diagnostics.Process.Start(procInfo.FileName);


}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}


Please assist

Regards
Shantanu
 
M

mgsram

Hi all
i am trying to imolement a code to run a batch file. But its throwing
error

"No application is associated with the specified file for this
operation"

The code which i am implementing is

private void InstallDefectService()
{
try
{

string strFilePath = @"C:\Program Files\adi
\DefectTrackingCOMAddinSetup\InstallService.bat";

System.Diagnostics.Process ProcService = new
System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo procInfo = new
System.Diagnostics.ProcessStartInfo();

procInfo.UseShellExecute = true;

procInfo.FileName = strFilePath;

ProcService = System.Diagnostics.Process.Start(procInfo.FileName);

}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

Please assist

Regards
Shantanu


I dont think there is any problem in the code. It looks alright. Can u
shorten to path and check. i.e. instead of spaces can u have something
like c:\InstallService.bat. Perhaps you may have to change to Progra~1
instead of Program Files.
 
J

Jon Skeet [C# MVP]

shantanu said:
i am trying to imolement a code to run a batch file. But its throwing
error

"No application is associated with the specified file for this
operation"

I don't *think* you can run batch files directly as processes. You need
to start the appropriate shell (eg cmd.exe) and pass it into that.
 
W

Willy Denoyette [MVP]

shantanu said:
Hi all
i am trying to imolement a code to run a batch file. But its throwing
error

"No application is associated with the specified file for this
operation"

The code which i am implementing is

private void InstallDefectService()
{
try
{

string strFilePath = @"C:\Program Files\adi
\DefectTrackingCOMAddinSetup\InstallService.bat";

System.Diagnostics.Process ProcService = new
System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo procInfo = new
System.Diagnostics.ProcessStartInfo();

procInfo.UseShellExecute = true;

procInfo.FileName = strFilePath;


ProcService = System.Diagnostics.Process.Start(procInfo.FileName);


}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}


Please assist

Regards
Shantanu



Should work, a .bat file is by default associated with the cmd interpreter.
the "assoc .bat" command should return:
..bat=batfile

Willy.
 
M

mgsram

Should work, a .bat file is by default associated with the cmd interpreter.
the "assoc .bat" command should return:
.bat=batfile

Willy.


Actually I just tried with a test batch file and indeed it worked.
 

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