0

I am trying to execute a batch file with the given code below

private void buttonDisable_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process si = new System.Diagnostics.Process();
            si.StartInfo.FileName = "Q:\\disable.bat";
            si.Start();          
        }

But it just comes up with this error :

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll

Additional information: The system cannot find the file specified

The file does exist in the location

Community
  • 1
  • 1

2 Answers2

0

The likely explanation for this problem is that the user context that executes the code does not have the Q drive mapped. So, in other words, you can see the file, but the executing code cannot. Perhaps this is running under ASP.net, for instance.

The other plausible explanation is simply that the file does not exist.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

that's normal because .bat is not a process

    System.Diagnostics.Process.Start("cmd.exe", @"/c Q:\disable.bat")  

could you please try this link

http://www.codeproject.com/Articles/90143/Mapping-Network-Drive-using-C

if you can force the drive mapping I think you will be able to access the drive

BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47