Solved

Resizing Command Prompt Windows that are opened programmatically

Posted on 2009-05-14
5
336 Views
Last Modified: 2012-05-07
I have a program that reads a list of codes and sequentially launches corresponding .bat files using the System.Diagnostics.Process.Start method and then does a procID.waitforexit() before launching the next .bat file in sequence.

When the .Start method opens the command prompt window and launches the .bat file, the window partially covers the main program's window.  Moving the newly opened window does not cause the main program to repaint the window thereby leaving blank spaces denying the user from seeing the main program's status messages.  I'm pretty certain that the waitforexit() function is put the main program into an idle state to the point where it will not process any screen painting commands.

Is there anyway to:
a) control the position of the new process's window, or,
b) loop around the waitforexit() giving it a 500 millisecond pause time and call a DoEvents() inside the loop so that the program can repaint its status messages?

Ideally I'd like to do both, but I will settle for only (b).

Thanks in advance!

Colby
The Not-So-Big Cheese
0
Comment
Question by:ksi-tech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:Zoooink
ID: 24386206
do you need to see the information on the batch files? Because you could initiate the minimize property for each batch file launched?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24387740
You can poll using code like this:

        Dim p As New Process
        p.StartInfo.FileName = "c:\someFile.bat"
        p.Start()
        While Not p.HasExited
            System.Threading.Thread.Sleep(50) ' reduce cpu usage
            Application.DoEvents() ' keep app responsive
        End While
        ' ...continue with code..

0
 

Author Comment

by:ksi-tech
ID: 24387748
Zoooink, I had thought about doing this, but, my client's policy is to be able to see everything that is happening while it is happening and so this was dismissed early in the project.

Thank you for your comment!

Colby
0
 

Author Closing Comment

by:ksi-tech
ID: 31581515
IdleMind,
Thanks for your code snippet.  I wasn't sure about whether to check the status of the WaitForExit which returns a true/false or if there was another method or property that could be checked.

Colby
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24387891
Right...the loop itself can be written other ways:

        p.Start()
        Do
            Application.DoEvents()
            p.WaitForExit(50)  ' <-- basically equivalent to my Thread.Sleep() call
        Loop While Not p.HasExited
        ' ...continue with code..

Other options include:
(1) Turn on EnableRaisingEvents() and subscribe to the Exited() event:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim p As New Process
        p.StartInfo.FileName = "c:\someFile.bat"
        p.EnableRaisingEvents = True
        AddHandler p.Exited, AddressOf P_Exited
        p.Start()
    End Sub

    Private Sub P_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
        ' ...continue with code here...
    End Sub

(2) Execute the Process.Start() in another thread so you can use WaitForExit() without locking up the main GUI.  Encapsulate that in a seperate class so you can raise an event from it.  This requires you to use Delegates/Invoke though...or you could encapsulate a BackgroundWorker component.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft Access combo box help 2 52
Access 2013 combo box not working 3 58
passing a value with stream reader AFTER a ";" 3 83
Spell Check in VB6 13 137
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question