How to get the cmd prompt to run in hidden mode when calling a .bat file?

dhuygu

Member
Joined
Sep 25, 2006
Messages
10
Programming Experience
Beginner
I call .bat file from my vb.net application.But I dont know How to get the cmd prompt to run in hidden mode when calling a .bat file? help me please...
 
Create an instance of the ProcessStartInfo class where you set its WindowStyle property to Hidden, supply this instance to the Process.Start method.
 
Works fine here, what's your code?
 
VB.NET:
Dim psInfo As New System.Diagnostics.ProcessStartInfo("D:\batch.bat")
psInfo.WindowStyle = ProcessWindowStyle.Hidden
System.Diagnostics.Process.Start(psInfo)
 
Last edited by a moderator:
Yes, start's the code. Perhaps your batch file makes a call to an application that starts itself a new process/window?
 
I created a txt file.I wrote my db2 commands in it.Then I created batch.bat file contains :
db2cw db2 -td! -f "C:\copy.txt" in it.
Then I call my batch file from my application.
 
If that command produces a new window that could be why. Try running that command with the PSI-hidden directly instead of through the batch command window. Remember separating the command from arguments, like: New PSI("appProcess.exe", "-argu -ments")
 
You are starting a process of a batch file, which in turn probably call a new process start employs it own window that does not hide. My suggestion is that you start this process directly, instead of starting 'my.bat' that calls 'my.exe -param' you start 'my.exe -param' directly with the Hidden directive.
 
it is not possible because I call .txt file not an .exe file from batch file.
I want to ask another question.
For example an error occurred while my application running.On command prompt window error will be written.is it possible to show error in my application? because if I hide command prompt window it is not possible to know if an error occurred or not or what error occurred.
http://www.vbdotnetforums.com/newreply.php?do=newreply&noquote=1&p=41660
 
It is possible to do as I said because each line in a batch file is a command to be executed and each and all of these commands can be started with the Process.Start method.

For errors there are two options; check out the RedirectStandardOutput property of ProcessStartInfo class, this enables you to get the text normally written to the console window. Other, the ExitCode property of Process class can give you some information, a successful execution usually return zero.
 
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2][COLOR=#000000] proc [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#000000] Process = [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2][COLOR=#000000] Process[/COLOR][/SIZE]
[SIZE=2]proc.StartInfo.FileName = [/SIZE][SIZE=2][COLOR=#800000]"C:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe"[/COLOR][/SIZE]
[SIZE=2]proc.StartInfo.Arguments() = [/SIZE][SIZE=2][COLOR=#800000]" connect to myDB"[/COLOR][/SIZE]
[SIZE=2]proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden[/SIZE]
[SIZE=2]proc.Start()[/SIZE]

But still can not hide window :(...
thanks for your helps....

 
Perhaps because db2cmd.exe opens a new db2 command window? I found that -i switch with this console app inherits and shares the (cmd.exe) command prompt window. Try it, I haven't got this application. Ref: http://publib.boulder.ibm.com/infoc...?topic=/com.ibm.db2.udb.doc/core/r0002036.htm
I'm not 100% certain what exactly they mean with "invokes cmd.exe", but there is a slight possibility that this command have to be issued from an existing cmd.exe console session, in which case the process call must be on 'cmd.exe' with parameter /c or /k to invoke the "db2cmd.exe -i {and your params}".
 
Back
Top