c.haslam

A simple _Set_timer script: timeout

3 posts in this topic

#1 ·  Posted (edited)

The following code is my attempt to check whether a user inserts a CD or USB stick (drive E:) within 15 seconds, but it doesn't work:

Opt('TrayIconDebug')
#include <timers.au3>
$hGUI = GUICreate("Simple timer", 400, 320)
GUISetState(@SW_SHOW)
$timer = _Timer_SetTimer($hGUI, 3000, "Check_mounted") ; create timer
$secs = 0

Func Check_mounted($hWnd, $iMsg, $iIDTimer, $iTime)
    #forceref $hWnd, $iMsg, $iIDTimer, $iTime
    $result = ''
    If FileExists('E:\') Then
        $result = 'loaded'
    Else
        $secs += 3
        If $secs=15 Then
            $result = 'timed out'
        EndIf
    EndIf
    If $result<>'' Then
        MsgBox(0,'',$result)
        _Timer_KillTimer($hGUI,$timer)
        GUIDelete($hGUI)
    EndIf
EndFunc

 

Perhaps I have a stupid bug, or perhaps not. Suggestions?

Edited by c.haslam
added parameters to Check_mounted(), added sleep(5000)

Spoiler

CDebug Dumps values of variables including arrays, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

There are more elegant ways of checking for cd's and Sticks.

Search the helpfile for Drive or Removable Drive...

For Instance - _WinAPI_IsDoorOpen

Edit: DriveStatus looks like it would work well here.

Edited by l3ill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

My actual objectives::

  • Come up with as simple an example as possible for _Timer_SetTimer() being used for an external event  timing out
  • Sometimes RunWait() hangs up when doing schtasks.exe. I am trying to code telling the user when it has hung, and hopefully to figure out why/when it hangs up.

I posted the above code as easier to work with than the actual case.

Edited by c.haslam

Spoiler

CDebug Dumps values of variables including arrays, to a GUI, to the Console, and to the Clipboard

 

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