Jump to content

Need Help WIth SLEEP Command


Guest TiM
 Share

Recommended Posts

:ph34r: This is my problem. We use a piece of security software on our public access computers and from time to time this window gets left open which will allow the user to do harmful things to the machine. I created a script that starts when the machine does to watch when the window opens and then close it after a specified amount of time. It works great except if you close the window and then open it back up before the specified time has expired, the window will close too soon. Example; say the window is set to close 60 minutes after it is first opened. You open the window and after 30 minutes you close it. 25 minutes later you open it again and start working but the window closes after 5 minutes. It seems that once a sleep command is used, it continues to pause the script until it expires. If you happen to reopen the window after it runs down, it works fine. Is their some way to work around this problem. I havent been able to find a way myself and would appreciate any suggestions. My script looks like this.

Opt("TrayIconHide", 1)

WinWaitActive("Untitled - Notepad")

If WinExists("Untitled - Notepad") Then

sleep(30000)

WinClose("Untitled - Notepad", "")

ENDIF

WinActivate("Notepad", "No")

Send("n")

WinWaitClose("Untitled - Notepad")

Run("Closewindow.exe", "C:\TEMP", @SW_HIDE)

Link to comment
Share on other sites

You could do an IF clause with NOT(WinWaitClose ( "title" [, "text" [, timeout]] )), setting your desired timeout. If that timeout runs off, you close the window "by script" , but if the window is closed by hand, then you start the timeout again.

To do this, embed the IF clause into a While(1) loop and do nothing in the ELSE clause.

While (1)
    WinWaitActive ( "Untitled - Notepad" )
    If NOT ( WinWaitClose ( "Untitled - Notepad", "", 30 ) ) Then
  WinClose ( "Untitled - Notepad")
    EndIf
WEnd
Edited by Proof
Link to comment
Share on other sites

:ph34r::(

Thank you very very much for your help Proof. It works like a charm. It's people like yourself that make the world a better place to work in. I'm pretty new to this scripting stuff but you hit the nail on the head. Thanks Again! TiM

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