[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Resizing Command Prompt Windows that are opened programmatically

Posted on 2009-05-14
5
Medium Priority
?
354 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
  • 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 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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 86

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

834 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