Jump to content
Sign in to follow this  
acoustique

_WinAPI_EnumWindows()

Recommended Posts

acoustique

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

Share this post


Link to post
Share on other sites
acoustique

acoustique

Welcome to the forum!

Example :mellow:

So if I call _EnumWindows as mentioned in example link it will work even when PC is logged off?

Share this post


Link to post
Share on other sites
acoustique

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?

Share this post


Link to post
Share on other sites
ProgAndy

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

Share this post


Link to post
Share on other sites
LarryDalooza

This comes up time and again...

The desktop of the user that the script runs as is where the windows come. The SYSTEM or NETWORKSERVICE or like context does not have access to any desktop.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.