Jump to content

Improper Processexists


 Share

Recommended Posts

$RarSlave = Run(@ComSpec & ' /c "' & @StartupDir & '\rarslave.exe" > RarSlave.log', @MyDocumentsDir, @SW_HIDE)
    WinActivate($RarSlave)

      ;Show GUI and so forth

    While ProcessExists($RarSlave)
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case Else
           ;;;
        EndSelect
    WEnd

It initiates the WEnd statement while the Process still exists.

Link to comment
Share on other sites

Do you mean that it exits while the process still exists? I see a gui loop with no gui functions, so assuming this is only part of the script. I see no winwait so winactivate is a maybe chance of happening.

Edited by MHz
Link to comment
Share on other sites

Do you mean that it exits while the process still exists? I see a gui loop with no gui functions, so assuming this is only part of the script. I see no winwait so winactivate is a maybe chance of happening.

Previously, my coding created a seperate batch file, ran it, and monitored it's closing. Now the goal is watching the internally created external console box's closing. I don't see what I need to modify. :think:

$RarSlave = Run(@ComSpec & ' /c "' & @StartupDir & '\rarslave.exe" > RarSlave.log', @MyDocumentsDir, @SW_HIDE)
    WinActivate($RarSlave)
    $Rver = FileGetVersion("rarslave.exe")
    If Not WinGetState($RarSlave) = 16 Then WinSetState($RarSlave, "", @SW_MINIMIZE)
    #include <GuiConstants.au3>
    GUICreate("PC Off after RarSlave", 235, 90, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST)
    GUISetIcon("G:\AutoIt Projects\RSshutdwn\protect green.ico")
    GUISetCursor(0)
    GUISetBkColor(0x808080)
    $Label_1 = GUICtrlCreateLabel("RarSlave v" & $Rver & " is running !", 45, 10, 240, 20)
    $ShutIt = GUICtrlCreateCheckbox("Shut Down PC after RarSlave", 40, 30, 170, 16)
    $Label_2 = GUICtrlCreateLabel("RarSlave output is in My Documents", 30, 71, 240, 20)
    $DispLog = GUICtrlCreateCheckbox("Display log on start up", 40, 51, 170, 16)
    GUICtrlSetState($ShutIt, $GUI_CHECKED)
    GUICtrlSetState($DispLog, $GUI_CHECKED)
    GUISetState(@SW_SHOW)
    While ProcessExists($RarSlave)
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case Else
            ;;;
        EndSelect
    WEnd
    GUISetState(@SW_HIDE)
    If GUICtrlRead($DispLog) = 1 Then
        FileCreateShortcut(@ScriptFullPath, @StartupDir & "\ShowLog.lnk", "C:\", "ShowLog", "Show RarSlave Output Log")
    EndIf
    If GUICtrlRead($ShutIt) = 1 Then
        If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
        Send("{SHIFTDOWN}")
        Send("{SHIFTUP}")
        $iMsgBoxAnswer = MsgBox(4145, "PC Shut Down !!", "This computer is about to SHUT DOWN." & @CRLF & "You have 20 seconds to modify this." & @CRLF & "To NOT shut down, click Cancel.", 20)
        Select
            Case $iMsgBoxAnswer = 1;OK
                Shutdown(9)
            Case $iMsgBoxAnswer = 2;Cancel
                Exit
            Case $iMsgBoxAnswer = -1;Timeout
                Shutdown(9)
        EndSelect
        
    Else
        If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(8484, "Shutdown Cancelled", "Computer shut down was not selected when RarSlave" & @CRLF & "ended.  Do you want to shut this PC down ?", 10)
        Select
            Case $iMsgBoxAnswer = 6;Yes
                Shutdown(9)
            Case $iMsgBoxAnswer = 7;No
                Exit
            Case $iMsgBoxAnswer = -1;Timeout
                Exit
        EndSelect
    EndIf
Link to comment
Share on other sites

I can see that you are using the ProcessID from the Run() function as a window title. This cannot work. I have changed the titles to a classname to recognize the console window. I figure that was your issue.

Try this:

Opt('WinTitleMatchMode', 4)

; Console Window
$WinRarSlave = "classname=ConsoleWindowClass"
$Pid = Run(@ComSpec & ' /c "' & @StartupDir & '\rarslave.exe" > RarSlave.log', @MyDocumentsDir, @SW_HIDE)
WinActivate($WinRarSlave)
$Rver = FileGetVersion("rarslave.exe")
If Not WinGetState($WinRarSlave) = 16 Then WinSetState($WinRarSlave, "", @SW_MINIMIZE)

; Create the Gui
#include <GuiConstants.au3>
GUICreate("PC Off after RarSlave", 235, 90, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOPMOST)
GUISetIcon("G:\AutoIt Projects\RSshutdwn\protect green.ico")
GUISetCursor(0)
GUISetBkColor(0x808080)
$Label_1 = GUICtrlCreateLabel("RarSlave v" & $Rver & " is running !", 45, 10, 240, 20)
$ShutIt = GUICtrlCreateCheckbox("Shut Down PC after RarSlave", 40, 30, 170, 16)
$Label_2 = GUICtrlCreateLabel("RarSlave output is in My Documents", 30, 71, 240, 20)
$DispLog = GUICtrlCreateCheckbox("Display log on start up", 40, 51, 170, 16)
GUICtrlSetState($ShutIt, $GUI_CHECKED)
GUICtrlSetState($DispLog, $GUI_CHECKED)
GUISetState(@SW_SHOW)

; Loop while rarslave.exe exists
While ProcessExists($Pid)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case Else
    ;;;
    EndSelect
WEnd

; Hide the Gui
GUISetState(@SW_HIDE)

; Create shortcut to Log file
If GUICtrlRead($DispLog) = $GUI_CHECKED Then
    FileCreateShortcut(@ScriptFullPath, @StartupDir & "\ShowLog.lnk", "C:\", "ShowLog", "Show RarSlave Output Log")
EndIf

; Prepare for shutdown
If GUICtrlRead($ShutIt) = $GUI_CHECKED Then
    If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
    Send("{SHIFTDOWN}{SHIFTUP}")
    $iMsgBoxAnswer = MsgBox(4145, "PC Shut Down !!", "This computer is about to SHUT DOWN." & @CRLF & "You have 20 seconds to modify this." & @CRLF & "To NOT shut down, click Cancel.", 20)
    Select
        Case $iMsgBoxAnswer = 1;OK
            Shutdown(9)
        Case $iMsgBoxAnswer = 2;Cancel
            Exit
        Case $iMsgBoxAnswer = -1;Timeout
            Shutdown(9)
    EndSelect
    
Else
    If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(8484, "Shutdown Cancelled", "Computer shut down was not selected when RarSlave" & @CRLF & "ended.  Do you want to shut this PC down ?", 10)
    Select
        Case $iMsgBoxAnswer = 6;Yes
            Shutdown(9)
        Case $iMsgBoxAnswer = 7;No
            Exit
        Case $iMsgBoxAnswer = -1;Timeout
            Exit
    EndSelect
EndIf
Link to comment
Share on other sites

I can see that you are using the ProcessID from the Run() function as a window title. This cannot work. I have changed the titles to a classname to recognize the console window. I figure that was your issue.

Try this:

Opt('WinTitleMatchMode', 4)
{Cut for space}

That may be one of the problems, but it still doesn't detect the console window. :think:

I'm going to try to set a temporary pause (or two) to see if it's a problem with the Console window creation itself.

Thank you for your help, though ! :(

Link to comment
Share on other sites

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...