For example i have this code:
Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName
What you want to do is embed the .bat file as an embedded resource as coshmos suggested. To do this you need to right click on the .bat file in the solution explorer, select properties, and then under "Build Action" section select "Embedded Resource". After that, assuming your bat file is in the program's root directory, the following code should work:
string batFileName = "dxdiag.bat";
string programName = Assembly.GetExecutingAssembly().GetName().Name;
using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream(programName + "." + batFileName))
{
using (TextReader tr = new StreamReader(input))
{
File.WriteAllText(batFileName, tr.ReadToEnd());
}
}
Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = batFileName;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
proc.Close();
The first half of this code pulls the bat file out of the embedded resources and saves it as an actual, but temporary, bat file in the programs root directory. After that it is basically the same as your code.
Additionally if you add File.Delete(batFileName); after this code, it will automatically delete the temporary bat file it created.