Jump to content

_WinAPI_EnumWindows()


Recommended Posts

Hi I have written the following function -

;Function to Enumerate windows and return handle of the windows with same process id

Func EnumerateWindows()
    $aWindows = _WinAPI_EnumWindows()

    For $iCnt = 1 To UBound($aWindows) - 1
    ;Current handle
        $l_hHandle = $aWindows[$iCnt][0]
        
    ;Current PID
        _WinAPI_GetWindowThreadProcessId($l_hHandle,$l_pPID)
        
    ;If current PID and clnpack PID match we have a valid handle
[b]     if($l_pPID == $l_pidProcess) Then;Here I am checking which windows belong to my process[/b]
            Return $l_hHandle       
        Else
            ContinueLoop
        EndIf
    Next
    
    Return 0
EndFunc

The above function returns a handle each time a window handle belonging to my process ($l_pidProcess) is found. It returns 0 if no windows belonging to my process are found. I am using Windows XP SP2. Now my problem is that this function works perfectly when I am logged on or when the machine is locked but it returns 0 (function failed) when I log off from the machine(machine still running). I have a requirement where the above function must work even after the machine has been logged off. Can anyone please help me out here? The problem obviously lies with the _WinAPI_EnumWindows() API call...

Link to comment
Share on other sites

I believe services can run when users are logged off. So if you were to run it as a service...

@AgentSmith : Thanks. I guess that will be the last option to try.

@raisim : I tried your example. It works fine when I am logged on or the machine is locked. However, when I logoff from the machine it does not work. I am sure the script is running because I have added Beep() and can hear the machine beeping. However the EnumWindows API fails when the machine is logged off.

Anyone know a workaround for this problem?

Link to comment
Share on other sites

if noone is logged on, there are no windows ...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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