Results 1 to 14 of 14

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

  1. #1
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149

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

    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...

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    Create an instance of the ProcessStartInfo class where you set its WindowStyle property to Hidden, supply this instance to the Process.Start method.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  3. #3
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149
    I tried but still I can not run cmd prompt window in hidden mode.

  4. #4
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    Works fine here, what's your code?
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  5. #5
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149
    Code:
     
    Dim psInfo As New System.Diagnostics.ProcessStartInfo("D:\batch.bat")
    psInfo.WindowStyle = ProcessWindowStyle.Hidden
    System.Diagnostics.Process.Start(psInfo)
    Last edited by JohnH; 09-26-2006 at 4:50 AM. Reason: code box

  6. #6
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    Yes, start's the code. Perhaps your batch file makes a call to an application that starts itself a new process/window?
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  7. #7
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149
    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.

  8. #8
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    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")
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  9. #9
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149
    I couldnt understand what you mean.Can you please explain again?
    thanks for your helps....

  10. #10
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    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.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  11. #11
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149
    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.

  12. #12
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    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.
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

  13. #13
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Sep 2006
    Posts
    10
    Reputation
    149
    Code:
    Dim proc As Process = New Process
    proc.StartInfo.FileName = "C:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe"
    proc.StartInfo.Arguments() = " connect to myDB"
    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    proc.Start()
    But still can not hide window ...
    thanks for your helps....


  14. #14
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,209
    Reputation
    2859
    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/infoce...e/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}".
    [xcode=vb] code here [/xcode] - see bbcode list or use formatting buttons in posting editor.

    Visual Studio Community 2017

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •