473,685 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.e xe 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.Diagnost ics.ProcessWind owStyle.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(s etpath("tuneup. bat"));
}

the ..setpath("tune up.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 3182
Charles,

Create a ProcessStartInf o instance with the path of the batch file to
run and whatnot. Also, set the UseShellExecute property on the
ProcessStartInf o 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.co m

"Charles" <ne*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.e xe 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.Diagnost ics.ProcessWind owStyle.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(s etpath("tuneup. bat"));
}

the ..setpath("tune up.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
2572
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 functionality simply doesn't exist anymore in Windows 2000 or above. I did find a work-around to this that I thought y'all might want to know about. There are a number of new fetures in batch files available on Windows 2000 including an extended syntax...
2
2785
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 : Variable = vbc Value = C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe But when I try to make an assembly of myself by using the following command
3
2286
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 "D:\". at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.Directory.InternalCreateDirectory(String fullPath, String path) at System.IO.Directory.CreateDirectory(String path) at TestVBProject.createdirectorytest.Page_Load(Object...
3
2660
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 (win XP), and remoting is working fine, but yesterday we attempted to install our application on our shared server and we keep getting 401 - Not Authorized errors whenever a remoting call is made. To get the application to the server, we got...
4
1899
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 had a full path to an MDB file woth no space characters, and I couldn't open it by dragging it to a shortcut to msaccess.exe. It turns out the problem was that the path had "-" charactrers, and Windows didn't put quotes around the path for me...
4
6427
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 thinking the following might help. I would appreciate if someone could comment on this idea and possibly suggest a better one: The environement variable in question is 'Path' in the HKCU registry folder's Environment key. I want to add some...
3
4461
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 cmd.exe with ASPNET as a user. But nothing happens. It can't execute the batch file. This is the code i am using to run the batch file:
5
3446
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 "notes" not being the issue). Beginning with... Dim objProcess As Process Dim objProcessStartInfo As New ProcessStartInfo
7
2082
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 the script because I want to take advantage of the /K option, so that the log will be onscreen. And second the batch file must be able to call other batch files in a cascading effect. Which it isn't able to do. So when I run the follow...
0
8570
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8925
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5790
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4521
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.