Results 1 to 3 of 3

Thread: System.Dianostics.Process.StartInfo.WindowMode = ...Hidden doesn't work

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Resolved System.Dianostics.Process.StartInfo.WindowMode = ...Hidden doesn't work

    I am trying to get my program to execute a command line program, retrieve the results, process them and return them to a user from my program. However, it all works fine except that it doesn't hide the command window. It always appears, you can't see anything on it because it is redirected to my program and I have no idea how to stop it. I tried it with even just a simple batch file with nothing more than
    Code:
    @echo off
    echo Hello World
    in it and it still displays the window.

    How can I prevent it from displaying the window?

    Note: Using shell is not an option because shell doesn't redirect the output.

    Code:
    VB Code:
    1. Dim Process As New Process 'Creates a new process
    2. Dim StreamOut As IO.StreamReader 'Creates a stream reader to read the stream from the command
    3. Dim Output As CommandOutput 'Holds the output from the command
    4.  
    5. '
    6. 'Creates the shutdown process
    7. Process.StartInfo.FileName = "C:\Echo.bat"
    8. Process.StartInfo.UseShellExecute = False
    9. Process.StartInfo.RedirectStandardOutput = True
    10. Process.StartInfo.RedirectStandardError = True
    11. Process.StartInfo.RedirectStandardInput = True
    12. Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 'Hides the window from the user
    13. Process.Start() 'Executes the process
    14.  
    15. StreamOut = Process.StandardOutput 'Retrieves the output from the process
    16. Process.WaitForExit(2000) 'Waits for 20 seconds for the process to finish
    17.  
    18. Output = ProcessOutput(StreamOut.ReadToEnd) 'Converts the output from the command to CommandOutput
    19. StreamOut.Close() 'Closes the stream reader
    Last edited by Ideas Man; Nov 21st, 2004 at 04:31 AM.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Add this line:
    Process.StartInfo.CreateNoWindow = True
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    Thanks Lunatic3, you legend. I saw that and I thought about it and for some reason, decided against it, wish I hadn't. Thanks again.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

Posting Permissions

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



Click Here to Expand Forum to Full Width