Sign in to follow this  
Followers 0
Casey

Array / PID question

5 posts in this topic

#1 ·  Posted (edited)

After some more work I have revised my question as I have scrapped the concept of identifying the title by seeking a reference to it from the PID. I have a section of code that looks for missing windows and if found replaces them. This is to make sure that I have the number of ghostcast sessions that were spawned by the script at first run. It makes up for end-user interaction.

I think that I am close. The logic is this:

1. Create array that will be later populated

2. swap the contents of a variable into that array at a specified position that matches the missing windows unique number.

3. Read the finished array from top to bottom in sequence and if the element numerical value does not match its positions numerical value execute the command to spawn a new process

4. name the title of the new process

If zero is missing in position zero all works, however, it then ignores a missing value of 2 and instead uses zero again. I assume line 63 is where I am off but I don't understand why.

Please advise.

#RequireAdmin
#include <Array.au3>

Global $Name , $NameN

$Name = "780_"  ; _WinDeriveName(): first part of active ghost session windows previously named with _WinSetName()
$NameN = "5"    ; _WinDeriveName(): Start position for StringMid

Opt("WinTitleMatchMode", 1)

$list = ProcessList("GhostSrv.exe") ; Create Array of active GhostSrv.exe processes
;_ArrayDisplay($list,"Line 12")
$RCount = $list[0][0]   ; Get real number of running GhostSrv.exe processes
$RCountErr = @error ; I haven't got to error handling yet

Select
    Case $RCountErr = 1
        _780()
        _WinSetName()
    Case $RCount = 0    ; No processes, spawn all and rename titles
        _780()
        _WinSetName()
    Case Else
        _WinDeriveName() ; There are GhostSrv.exe processes
EndSelect

Func _WinDeriveName()
        Local $Titles[21]   ; Create array to store query results
        $Titles[0] = "0"
        $Titles[1] = ""
        $Titles[2] = ""
        $Titles[3] = ""
        $Titles[4] = ""
        $Titles[5] = ""
        $Titles[6] = ""
        $Titles[7] = ""
        $Titles[8] = ""
        $Titles[9] = ""
        $Titles[10] = ""
        $Titles[11] = ""
        $Titles[12] = ""
        $Titles[13] = ""
        $Titles[14] = ""
        $Titles[15] = ""
        $Titles[16] = ""
        $Titles[17] = ""
        $Titles[18] = ""
        $Titles[19] = ""
        $Titles[20] = ""
        ;_ArrayDisplay($Titles,"Line 50") ;comment this out
        $DTitle = WinList() ; windows to array
        For $i = 0 To $DTitle[0][0] ; loop through array
            $DTitleN = WinGetTitle($DTitle[$i][0], "") ; assign tile to variable
            $SDTitleN = StringInStr($DTitleN, $Name) ; check to see if title match first part of what script sets at first run "780_"
            If $SDTitleN = "1" Then ; if match then
                $NDTitleN = StringMid($DTitleN, $NameN) ; get everything right of 780_. The unique number.
                $Arg = $NDTitleN
                _ArraySwap($Titles[$Arg], $Arg) ; insert the unique number into the array created in line 28 at the position = the unique number
                ;_ArrayDisplay($Titles,"Line 59") ;comment this out
                Sleep(50)
            EndIf
        Next
        ;_ArrayDisplay($Titles,"Line 66") ;comment this out
        ;For $element In $Titles  ; loop through array
        For $i = 0 to 20 Step 1 ;
            $s = _ArraySearch($Titles, $i) ; get position where $element resides
            If $s = -1 Then ; if there is no match while looping through the array
                $QPath_1 = IniReadSection(@ScriptDir & "\GHOST_SESSIONS.ini", "Path_1") ; Start obtaining setup info for command line to create new process (ghostcast session)
                $QPath_1e = $QPath_1[1][1]  ; obtianing UNC path from INI
                $QPath_1a = FileFindFirstFile($QPath_1e  & '*.gho') ; Obtaining the handle of the file name for the Ghost Image
                If $QPath_1a = -1 Then
                    ;MsgBox(0, "Error", "No files/directories matched the search pattern") ;Choose action to take
                    Exit
                EndIf
                $QPath_1b = FileFindNextFile($QPath_1a) ; Obtaining the actual Ghost Image file name
                FileClose($QPath_1a)    ; close the INI file
                $QSName_1 = IniReadSection(@ScriptDir & "\GHOST_SESSIONS.ini", "SName_1")   ; Obtaining more setup info for command line to create new process (ghostcast session)
                $QSName_1a = $QSName_1[1][1]    ; Obtain the ghostcast session name
                FileClose($QSName_1)    ; close the INI file
                $QCCOUNT_1a = "1"   ; Provide client count
                ShellExecute("ghostsrv", '"' & $QPath_1e & $QPath_1b & '"' & " " & $QSName_1a & " -UU" & " -R" & " -N" & $QCCOUNT_1a) ; execute ghostcast session creation              
                WinActivate ( "780 - Symantec GhostCast Server")
                WinWaitActive ( "780 - Symantec GhostCast Server" )
                WinSetTitle("780 - Symantec GhostCast Server", "", $Name & $i) ; Change title to match unique script name and number
                $QArg = $i
                _ArraySwap($Titles[$QArg], $QArg) ; insert the unique number into the array created in line 28 at the position = the unique number
                ;_ArrayDisplay($Titles,"Line 86") ;comment this out
            EndIf
        Next
EndFunc   ;==>_WinDeriveName


Func _WinSetName()
    Local $t, $WinSetName, $WinSetNameN
    $t = 1  ;counter
    $WinSetName = WinList()
    For $i = 1 To $WinSetName[0][0]
        $WinSetNameN = WinGetTitle($WinSetName[$i][0], "")
        If $WinSetNameN = "780 - Symantec GhostCast Server" Then
            WinSetTitle($WinSetNameN, "", $Name & $t)
            $t = $t + 1
        EndIf
    Next
EndFunc   ;==>_WinSetName


Func _780()
    ;....................................................................................................................
    ;                   Get Image File Name
    ;....................................................................................................................
    $Path_1 = IniReadSection(@ScriptDir & "\GHOST_SESSIONS.ini", "Path_1")
    $Path_1e = $Path_1[1][1]
    $Path_1a = FileFindFirstFile($Path_1e & "\*.gho")
    If $Path_1a = -1 Then
        ;MsgBox(0, "Error", "No files/directories matched the search pattern") ;Choose action to take
        Exit
    EndIf
    $Path_1b = FileFindNextFile($Path_1a)
    FileClose($Path_1a)
    ;....................................................................................................................
    ;                   Get Session Name
    ;....................................................................................................................

    $SName_1 = IniReadSection(@ScriptDir & "\GHOST_SESSIONS.ini", "SName_1")
    $SName_1a = $SName_1[1][1]
    FileClose($SName_1)
    ;....................................................................................................................
    ;                   Get Session Count
    ;....................................................................................................................
    $SCOUNT_1 = IniReadSection(@ScriptDir & "\GHOST_SESSIONS.ini", "SCOUNT_1")
    $SCOUNT_1a = $SCOUNT_1[1][1]
    FileClose($SCOUNT_1)
    ;....................................................................................................................
    ;                   Get Session Client Count
    ;....................................................................................................................
    $CCOUNT_1 = IniReadSection(@ScriptDir & "\GHOST_SESSIONS.ini", "CCOUNT_1")
    $CCOUNT_1a = $CCOUNT_1[1][1]
    FileClose($CCOUNT_1)
    ;....................................................................................................................
    ;                   Execute ghostsrv command line to create sessions
    ;....................................................................................................................
    For $i = 1 To $SCOUNT_1a
        ShellExecute("ghostsrv", '"' & $Path_1e & $Path_1b & '"' & " " & $SName_1a & " -UU" & " -R" & " -N" & $CCOUNT_1a)
        WinActivate ( "780 - Symantec GhostCast Server")
        WinWaitActive ( "780 - Symantec GhostCast Server" )
    Next
EndFunc   ;==>_780
Edited by Casey

Share this post


Link to post
Share on other sites



One and only bump. Thanks.

Share this post


Link to post
Share on other sites

I think (only a quick read so the following could be gibberish!) that line 63 is the problem because you are using for..in.

Suppose element 0 is 'abc' and array 2 is also 'abc'. _ArraySearch will return the first ocurance of 'abc' which is 0.

So I think either

you should use a for/next loop and then you know exactly which element you are looking at and you don't need _ArraySearch.

or

you should make sure you change the element value before you look for the next one so that _ArraySearch will not find it at the same index again.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ame='Casey' date='21 October 2010 - 05:28 PM' timestamp='1287678500' post='841742']

I think (only a quick read so the following could be gibberish!) that line 63 is the problem because you are using for..in.

Suppose element 0 is 'abc' and array 2 is also 'abc'. _ArraySearch will return the first ocurance of 'abc' which is 0.

So I think either

you should use a for/next loop and then you know exactly which element you are looking at and you don't need _ArraySearch.

or

you should make sure you change the element value before you look for the next one so that _ArraySearch will not find it at the same index again.

Martin,

Thanks for the reply. I seldom use arrays in what I have to do so they are a bit fuzzy to me. I took a break and re-read the help files and I saw exactly what your pointed out. I was also getting odd problems with WinList(). The problem looks to be with how the windows are created from the Shellexecute statement. With Symantec Ghost Cast Server the windows are not always active once created. They are there, selectable and functional, but not visible to WinList. I could not find a pattern other than the first window created by _780() never showed up in WinList after _WinSetName() had run. The meant that 780_1 which is the first windows was always recreated by _WinDeriveName() even if present. even if I brought the window to the forfront and then listed it again. Placing the WinActivate / WinWaitActive at the end of _780() immediately corrected the behavior. I find it odd that in _WinSetName() I am able to list and rename the window bit not any follow on attempts from _WinDeriveName().

I have modified what I posted for code to what appears to be working just in case it is useful to someone. Thanks again Martin.

Edited by Casey

Share this post


Link to post
Share on other sites

I have modified what I posted for code to what appears to be working just in case it is useful to someone. Thanks again Martin.

I take that back. The code works fine when logged into a system and executed from a compiled executable. However, I doesn't exhibit the same behavior when configured as a scheduled task.

When run from a scheduled task it hangs after the creation of the first ghost process at the WinWaitActive. Without it WinList doesn't do what I want. If thre is anyone who utilizes these options in a scheduled task would you please take a look and let me know what you think? Otherwise, I need to just scrap the project as not possible and move on.

Share this post


Link to post
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
Sign in to follow this  
Followers 0