Also, assuming it is indeed possible to do that, is there a way I can hide
the batch file window that opens so it just runs in the background? I've
messed around for hours with the System.Diagnostics.ProcessWindowStyle.Hidden
(and .Minimized) code but have determined that it must only be designed to
work with C# console applications and not windows applications.
Here is the code I'm using to run my batch files with the Click function of
my buttons at the moment, but I've tried many ways to do it:
/*Runs Tuneup.bat file*/
private void tuneupbtn_Click(object sender, EventArgs e)
{
Process.Start(setpath("tuneup.bat"));
}
the ..setpath("tuneup.bat").. portion of that is a method which comes from
another part of my program which sets the path of the file, regardless of
what the drive letter is. I had to do it this way because the program is
going to be ran from a USB flash drive so the drive letter will change
depending on the number of hard disks/partitions are there.
That being said - the button will run the batch file...problem is it tries
to run it as a C# console application (when it's written as a standard DOS
batch file) rather than using the windows shell, hence, it won't work.
Am I trying to do something that isn't possible? Am I going to have to
rewrite my batch files to run as a c# console application? Let me know if
anybody can help, thanks.
Charles Neitzel
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat");
myProcess.Start();
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
before the myProcess.Start(); this will had the command window but not what
ever is generated by the bat file.
Charles
I've tried putting in another argument line like this:
myProcess.StartInfo.Arguments = "tuneup.bat";
Putting that in there will make it so the window doesn't disappear and I can
actually use the command line. I can type tuneup.bat in there and it will
run the file just like it's supposed to, so the next problem comes in making
the program run it for me. Again I appreciate the help, I'm going to keep
messing with it to see if I can get it to work right. What am I missing?
Charles
myProcess.StartInfo.Arguments = "/c " + setPath("tuneup.bat");