Jump to content
Sign in to follow this  

Listen for File/Event

Recommended Posts

I'm trying to write a script that waits for a certain file to be used (it's a sound file that plays, and when that plays, I want my function to begin). It seems like it would have something to do with ProcessWait, or ProcessExists but I know the file does not show up as a process.

Anybody want to give me advice? I've been looking through the list of AutoIt functions and honestly couldn't find anything. Thanks.

Share this post

Link to post
Share on other sites

Getting a list of opened files is not easy at all. Very interesting though. Look what I found googling:


How does it work ?

OpenedFilesView uses the NtQuerySystemInformation API to enumerate all handles in the system. After filtering non-file handles, it uses a temporary device driver - NirSoftOpenedFilesDriver.sys for reading the information about each handle from the kernel memory. This device driver is automatically unloaded from the system when you exit from OpenedFilesView utility.

So I searched the forums for NtQuerySystemInformation and I found some stuff... but I simply can't understand it.

Take a look here as well:


And have this cool function by Larry <_<

Func CurrentCPU($init = 0)
    Global $liOldIdleTime = 0
    Global $liOldSystemTime = 0
    Local $SYS_BASIC_INFO = 0
    Local $SYS_TIME_INFO = 3
    $SYSTEM_BASIC_INFORMATION = DllStructCreate("int;uint;uint;uint;uint;uint;uint;ptr;ptr;uint;byte;byte;short")
    $status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYS_BASIC_INFO, _
            "ptr", DllStructGetPtr($SYSTEM_BASIC_INFORMATION), _
            "int", DllStructGetSize($SYSTEM_BASIC_INFORMATION), _
            "int", 0)
    If $status[0]Then Return -1
    While 1
        $SYSTEM_PERFORMANCE_INFORMATION = DllStructCreate("int64;int[76]")
        $SYSTEM_TIME_INFORMATION = DllStructCreate("int64;int64;int64;uint;int")
        $status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYS_TIME_INFO, _
                "ptr", DllStructGetPtr($SYSTEM_TIME_INFORMATION), _
                "int", DllStructGetSize($SYSTEM_TIME_INFORMATION), _
                "int", 0)
        If $status[0]Then Return -2
        $status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", $SYS_PERFORMANCE_INFO, _
                "ptr", DllStructGetPtr($SYSTEM_PERFORMANCE_INFORMATION), _
                "int", DllStructGetSize($SYSTEM_PERFORMANCE_INFORMATION), _
                "int", 0)
        If $status[0]Then Return -3
        If $init = 1 Or $liOldIdleTime = 0 Then
            $liOldIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1)
            $liOldSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2)
            If $init = 1 Then Return -99
            $dbIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1) - $liOldIdleTime
            $dbSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2) - $liOldSystemTime
            $liOldIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1)
            $liOldSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2)
            $dbIdleTime = $dbIdleTime / $dbSystemTime
            $dbIdleTime = 100.0 - $dbIdleTime * 100.0 / DllStructGetData($SYSTEM_BASIC_INFORMATION, 11) + 0.5
            Return $dbIdleTime
EndFunc   ;==>CurrentCPU

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...