?
Solved

Resizing Command Prompt Windows that are opened programmatically

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

649 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