Jump to content

Progress window with ProcessExists


Recommended Posts

I am running Microsoft's MBSA tool here and wanted the Progressbar to show up only until the time the ProcessExists "mbsacli.exe". Once it closes off, $Bar should also Hide.

doing something wrong here... When Button is clicked, process starts but it still goes on even after Process closes.

#include <Process.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>

$Form1 = GUICreate("Progress Test", 325, 121, -1, -1)
$Bar = GUICtrlCreateProgress(18, 26, 288, 20, $PBS_MARQUEE)
$Run = GUICtrlCreateButton("Run", 120, 72, 75, 25, $SS_CENTER)
$LblComplete = GUICtrlCreateLabel("Completed", 16, 32, 294, 17, $SS_CENTER)
GUICtrlSetFont($LblComplete, 11, 400, 0, "Arial")
GUICtrlSetState($LblComplete, $GUI_HIDE)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Run
            Do
                _SendMessage(GUICtrlGetHandle($Bar), $PBM_SETMARQUEE, True, 50)
                $Pid = Run(@ComSpec & ' /c "C:\Program Files\Microsoft Baseline Security Analyzer 2\MBSACLI" /xmlout /catalog C:\Temp\wsusscn2.cab /unicode /nvc >C:\Temp\Output.xml', "", @SW_HIDE)
            Until ProcessExists($Pid)
            
                ; $Bar should hide now...
                        ; GUICtrlSetState($Bar, $GUI_HIDE)
                ; $LblComplete should show now...
                        ;GUICtrlSetState($LblComplete, $GUI_SHOW)

    EndSwitch
WEnd

 

Link to comment
Share on other sites

Looks like no one ever responded. Give this a go

#include <Process.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>

Global $Pid = Null
$Form1 = GUICreate("Progress Test", 325, 121, -1, -1)
$Bar = GUICtrlCreateProgress(18, 26, 288, 20, $PBS_MARQUEE)
$Run = GUICtrlCreateButton("Run", 120, 72, 75, 25, $SS_CENTER)
$LblComplete = GUICtrlCreateLabel("Completed", 16, 32, 294, 17, $SS_CENTER)
GUICtrlSetFont($LblComplete, 11, 400, 0, "Arial")
GUICtrlSetState($LblComplete, $GUI_HIDE)
GUICtrlSetState($Bar, $GUI_HIDE)=

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Run
            $Pid = Run(@SystemDir & "\notepad.exe")
            _SendMessage(GUICtrlGetHandle($Bar), $PBM_SETMARQUEE, True, 50)
            GUICtrlSetState($Bar, $GUI_SHOW)
            GUICtrlSetState($LblComplete, $GUI_HIDE)


        Case Else
            If ($Pid) Then
                If (Not ProcessExists($Pid)) Then
                    $Pid = Null
                    GUICtrlSetState($Bar, $GUI_HIDE)
                    GUICtrlSetState($LblComplete, $GUI_SHOW)
                EndIf
            EndIf
    EndSwitch
WEnd

Store the PID In a global variable and throw it in the Else on the Switch. If the process has been started then check to see if it still exists. If it doesn't (Not Process Exists) then set PID back to Null and reset the bar/label

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...