472,371 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

problem with batch files in my C# windows application

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

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #1
1 2942
Charles,

Create a ProcessStartInfo instance with the path of the batch file to
run and whatnot. Also, set the UseShellExecute property on the
ProcessStartInfo instance to true, and the shell should process the batch
file, and it should work.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Charles" <ne*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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...
2
by: Rajesh Madhra | last post by:
Hi everybody I do not have Visual Studio. I only use Notepad and WebMatrix. My problems are : 1. I have DotNet Framework installed and it is working fine. I have Env. variable as follows :...
3
by: James Coleman | last post by:
Hello, The following error is appearing when attempting to create a directory using the availale system.io methods: System.IO.DirectoryNotFoundException: Could not find a part of the path...
3
by: Ron L | last post by:
I have an application that I am working on with 2 other developers. The applciation uses Remoting for our calls to SQL Server. We have been developing and testing against our development machines...
4
by: Steve Jorgensen | last post by:
Generally, it is the case that space characters in the names of things can cause difficulties, and removing the spaces can make things work more smoothly, but I recently found a reverse case. I...
4
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...
3
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...
5
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the...
7
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.