-4

I have a batch file with some code this batch file save in d: drive main root We want to execute this batch file when We double click or open d: drive please guide us how to achieve this We are waiting your response thanks.

echo off
SET PROG="c:\windows\system32\DCOM.exe"
echo pause
  • A batch file is an executable file just like any other. Google can tell you how to run an executable file in C# very effectively. – Servy Dec 31 '13 at 18:14
  • possible duplicate of [Launching a Application (.EXE) from C#?](http://stackoverflow.com/questions/240171/launching-a-application-exe-from-c) – John Kraft Dec 31 '13 at 18:16
  • we are not want to execute batch file in c# – user3143882 Dec 31 '13 at 18:18
  • no this is different question please check – user3143882 Dec 31 '13 at 18:20
  • 1
    When you tag something as **c#** or **vb.net** you are going to get answers about how to do it in c# or vb.net... that's kind of the purpose of tags. – jebar8 Dec 31 '13 at 18:39
  • 2
    I don't think it's possible to automatically run a batch file whenever you open a drive in Explorer. That would be dangerous. – jebar8 Dec 31 '13 at 18:42

1 Answers1

2

You can easily accomplish this using the Process Class in C#:

using System.Diagnostics;

namespace ConsoleApplication1
{
   class Program
   {
      static void Main(string[] args)
      {
        Process.Start(@"The path to your batch file goes here.");
      }
   }
}
Brian
  • 5,069
  • 7
  • 37
  • 47