I'm trying to write a windows application in C# (Using Microsoft Visual C#
2005 Express) that is nothing more than a simple UI with buttons on it. The
buttons do various things like running programs and executing registry
entries. The majority of my buttons work however, I have come upon a problem.
I need a few of the buttons to run DOS batch files, the batch files in turn
run program installers (specifically windows update runtime .exe files). The
batch files work the way I want them to when I execute them in windows,
however when I use my buttons in my C# program to run the batch files, they
run, but when the batch file that opens tries to run the installers, I get
errors for everything the batch file tries to run, be it installers, other
batch files, registry entries, etc. It appears as if it isn't opening an
actual batch file, but a C# console containing the code from the batch file.
The errors come out like this - KB896423.exe is the name of the file it is
trying to run:
"KB896423.exe is not recognized as an internal or external command, operable
program or batch file."
As I stated before, these batch files do work as long as they are executed
directly from windows...I just want my program to do it for me. I've searched
for days for help on this and can't find a solution - is this even possible?
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 6 11173
Try
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat");
myProcess.Start();
"Charles Neitzel" wrote: I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe files). The batch files work the way I want them to when I execute them in windows, however when I use my buttons in my C# program to run the batch files, they run, but when the batch file that opens tries to run the installers, I get errors for everything the batch file tries to run, be it installers, other batch files, registry entries, etc. It appears as if it isn't opening an actual batch file, but a C# console containing the code from the batch file. The errors come out like this - KB896423.exe is the name of the file it is trying to run: "KB896423.exe is not recognized as an internal or external command, operable program or batch file." As I stated before, these batch files do work as long as they are executed directly from windows...I just want my program to do it for me. I've searched for days for help on this and can't find a solution - is this even possible?
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
I did not notice the bit about the window not showing, to hide the command
window add
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.
"tony lock" wrote: Try
Process myProcess = new Process(); myProcess.StartInfo.FileName = "cmd.exe"; myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat"); myProcess.Start();
"Charles Neitzel" wrote:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe files). The batch files work the way I want them to when I execute them in windows, however when I use my buttons in my C# program to run the batch files, they run, but when the batch file that opens tries to run the installers, I get errors for everything the batch file tries to run, be it installers, other batch files, registry entries, etc. It appears as if it isn't opening an actual batch file, but a C# console containing the code from the batch file. The errors come out like this - KB896423.exe is the name of the file it is trying to run: "KB896423.exe is not recognized as an internal or external command, operable program or batch file." As I stated before, these batch files do work as long as they are executed directly from windows...I just want my program to do it for me. I've searched for days for help on this and can't find a solution - is this even possible?
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
I appreciate your time in responding to my questions. I have tried doing it
in a very similar way to that in the past and it hasn't seemed to work but
I'll give it a shot just the way you typed it and see how it works - I'll let
you know the outcome. Thanks.
Charles
"tony lock" wrote: I did not notice the bit about the window not showing, to hide the command window add
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.
"tony lock" wrote:
Try
Process myProcess = new Process(); myProcess.StartInfo.FileName = "cmd.exe"; myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat"); myProcess.Start();
"Charles Neitzel" wrote:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe files). The batch files work the way I want them to when I execute them in windows, however when I use my buttons in my C# program to run the batch files, they run, but when the batch file that opens tries to run the installers, I get errors for everything the batch file tries to run, be it installers, other batch files, registry entries, etc. It appears as if it isn't opening an actual batch file, but a C# console containing the code from the batch file. The errors come out like this - KB896423.exe is the name of the file it is trying to run: "KB896423.exe is not recognized as an internal or external command, operable program or batch file." As I stated before, these batch files do work as long as they are executed directly from windows...I just want my program to do it for me. I've searched for days for help on this and can't find a solution - is this even possible?
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
Ok so I'm making progress with that suggestion. I can get it to open the cmd
window at the appropriate directory, but it won't actually run the batch
file, it just disappears immediately (even after changing the
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; to
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
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
"Charles Neitzel" wrote: I appreciate your time in responding to my questions. I have tried doing it in a very similar way to that in the past and it hasn't seemed to work but I'll give it a shot just the way you typed it and see how it works - I'll let you know the outcome. Thanks.
Charles
"tony lock" wrote:
I did not notice the bit about the window not showing, to hide the command window add
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.
"tony lock" wrote:
Try
Process myProcess = new Process(); myProcess.StartInfo.FileName = "cmd.exe"; myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat"); myProcess.Start();
"Charles Neitzel" wrote:
> I'm trying to write a windows application in C# (Using Microsoft Visual C# > 2005 Express) that is nothing more than a simple UI with buttons on it. The > buttons do various things like running programs and executing registry > entries. The majority of my buttons work however, I have come upon a problem. > I need a few of the buttons to run DOS batch files, the batch files in turn > run program installers (specifically windows update runtime .exe files). The > batch files work the way I want them to when I execute them in windows, > however when I use my buttons in my C# program to run the batch files, they > run, but when the batch file that opens tries to run the installers, I get > errors for everything the batch file tries to run, be it installers, other > batch files, registry entries, etc. It appears as if it isn't opening an > actual batch file, but a C# console containing the code from the batch file. > The errors come out like this - KB896423.exe is the name of the file it is > trying to run: > "KB896423.exe is not recognized as an internal or external command, operable > program or batch file." > As I stated before, these batch files do work as long as they are executed > directly from windows...I just want my program to do it for me. I've searched > for days for help on this and can't find a solution - is this even possible? > > 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
The /c before the argument is important, it tells cmd.exe to to run the batch
file and then close, you cannot omit it. If you do as you found out you have
to type the command yourself, I do not know what's in your batch file. But a
simple file containing calc.exe as a command, certainly works in the way you
require, using the code I gave you. The calculator starts with out showing
the dos box and everything terminates when the bat file closes.
"Charles Neitzel" wrote: Ok so I'm making progress with that suggestion. I can get it to open the cmd window at the appropriate directory, but it won't actually run the batch file, it just disappears immediately (even after changing the myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; to myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
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
"Charles Neitzel" wrote:
I appreciate your time in responding to my questions. I have tried doing it in a very similar way to that in the past and it hasn't seemed to work but I'll give it a shot just the way you typed it and see how it works - I'll let you know the outcome. Thanks.
Charles
"tony lock" wrote:
I did not notice the bit about the window not showing, to hide the command window add
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.
"tony lock" wrote:
> Try > > Process myProcess = new Process(); > myProcess.StartInfo.FileName = "cmd.exe"; > myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat"); > myProcess.Start(); > > > "Charles Neitzel" wrote: > > > I'm trying to write a windows application in C# (Using Microsoft Visual C# > > 2005 Express) that is nothing more than a simple UI with buttons on it. The > > buttons do various things like running programs and executing registry > > entries. The majority of my buttons work however, I have come upon a problem. > > I need a few of the buttons to run DOS batch files, the batch files in turn > > run program installers (specifically windows update runtime .exe files). The > > batch files work the way I want them to when I execute them in windows, > > however when I use my buttons in my C# program to run the batch files, they > > run, but when the batch file that opens tries to run the installers, I get > > errors for everything the batch file tries to run, be it installers, other > > batch files, registry entries, etc. It appears as if it isn't opening an > > actual batch file, but a C# console containing the code from the batch file. > > The errors come out like this - KB896423.exe is the name of the file it is > > trying to run: > > "KB896423.exe is not recognized as an internal or external command, operable > > program or batch file." > > As I stated before, these batch files do work as long as they are executed > > directly from windows...I just want my program to do it for me. I've searched > > for days for help on this and can't find a solution - is this even possible? > > > > 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
Sorry just realised in copying the code into the note I left out the space
after the c it should read
myProcess.StartInfo.Arguments = "/c " + setPath("tuneup.bat");
"Charles Neitzel" wrote: Ok so I'm making progress with that suggestion. I can get it to open the cmd window at the appropriate directory, but it won't actually run the batch file, it just disappears immediately (even after changing the myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; to myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
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
"Charles Neitzel" wrote:
I appreciate your time in responding to my questions. I have tried doing it in a very similar way to that in the past and it hasn't seemed to work but I'll give it a shot just the way you typed it and see how it works - I'll let you know the outcome. Thanks.
Charles
"tony lock" wrote:
I did not notice the bit about the window not showing, to hide the command window add
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.
"tony lock" wrote:
> Try > > Process myProcess = new Process(); > myProcess.StartInfo.FileName = "cmd.exe"; > myProcess.StartInfo.Arguments = "/c" + setPath("tuneup.bat"); > myProcess.Start(); > > > "Charles Neitzel" wrote: > > > I'm trying to write a windows application in C# (Using Microsoft Visual C# > > 2005 Express) that is nothing more than a simple UI with buttons on it. The > > buttons do various things like running programs and executing registry > > entries. The majority of my buttons work however, I have come upon a problem. > > I need a few of the buttons to run DOS batch files, the batch files in turn > > run program installers (specifically windows update runtime .exe files). The > > batch files work the way I want them to when I execute them in windows, > > however when I use my buttons in my C# program to run the batch files, they > > run, but when the batch file that opens tries to run the installers, I get > > errors for everything the batch file tries to run, be it installers, other > > batch files, registry entries, etc. It appears as if it isn't opening an > > actual batch file, but a C# console containing the code from the batch file. > > The errors come out like this - KB896423.exe is the name of the file it is > > trying to run: > > "KB896423.exe is not recognized as an internal or external command, operable > > program or batch file." > > As I stated before, these batch files do work as long as they are executed > > directly from windows...I just want my program to do it for me. I've searched > > for days for help on this and can't find a solution - is this even possible? > > > > 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ccc |
last post by:
Good evening.
I was wonder how to write a batch file making no assumption if visual
studio is installed manually on the target system. I.e. it is likely
to map the visual studio.net file...
|
by: Herb Stevenson |
last post by:
Hello all. I need to set up a batch file to work w/ the Visual Studio.NET
2003 command prompt. However, when I run the batch file it uses the
standard command prompt. Is there a way to...
|
by: erniedude |
last post by:
Hi,
I'm a newbie and I was wondering if anyone knew a (Python) script to
run 4 batch files, one after the other (assuming the directories are
known). It would be better if all 4 batch files...
|
by: Steve Jorgensen |
last post by:
I remember that I used to set up utility batch files, and create Windows
shortcuts to them that would ask the user for parameters to supply to the
batch files. From what I can tell, this...
|
by: Charles |
last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual
C#
2005 Express) that is nothing more than a simple UI with buttons on it.
The
buttons do various things like running...
|
by: Shiraz |
last post by:
Hi
I'm using Visual Studio Installer to make my installer, and have not as yet
figured out a straightforward way to use it to set environmental variables.
Amongst the various things I tried, I'm...
|
by: emman_54 |
last post by:
Hi every one,
I am trying to run a batch file using my asp.net application.
I am using the Process class to run the batch file. When I run my web
application, In the task manager, i could see...
|
by: ee_stevek |
last post by:
hi guys,
here is my problem:
i have to maintain a web vb.net application developped some times ago.
The application was developped on Windows2000 SP3 with Visual Studio
2003 (7.1).
and the...
|
by: FireImp |
last post by:
So I've read a lot of post about how to run a batch file from within the C# program. And I followed the instructions with a few alterations to fit my needs. First I am using cmd.exe to actually run...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |