AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is it possible to exit a script by unplugging a USB stlck?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Jag02



Joined: 16 Apr 2008
Posts: 39

PostPosted: Fri May 30, 2008 10:31 am    Post subject: Is it possible to exit a script by unplugging a USB stlck? Reply with quote

Is it possible to exit several scripts by unplugging a USB stlck safely?
Back to top
View user's profile Send private message
Z Gecko
Guest





PostPosted: Fri May 30, 2008 1:17 pm    Post subject: Reply with quote

Yes, e.g. with IfExist
Back to top
Jag02



Joined: 16 Apr 2008
Posts: 39

PostPosted: Sat May 31, 2008 6:18 am    Post subject: Reply with quote

I am not very good at this so please could you work it out for me?
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1020
Location: The Interwebs

PostPosted: Sat May 31, 2008 8:40 am    Post subject: Reply with quote

Code:
Loop, ;can use settimer as well...
{
If !FileExist("path to USB drive here")
ExitApp
sleep, 5000 ;make smaller if you need it to exit sooner after removing drive, or larger if too many resources are being devoted to script
}
Back to top
View user's profile Send private message AIM Address
Lexikos



Joined: 17 Oct 2006
Posts: 2605
Location: Australia, Qld

PostPosted: Sat May 31, 2008 11:24 am    Post subject: Reply with quote

I think the point is to automatically exit the scripts when the user "safely removes" the USB stick. Since AutoHotkey.exe would be running off the stick, "safely remove" will fail and FileExist will continue to report that the drive exists. What we need to figure out is how to detect when the user wants to "safely remove," so we can automatically close the scripts and allow the stick to be removed.
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Sat May 31, 2008 12:39 pm    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/aa363215%28VS.85%29.aspx might be the way to go.
Back to top
Z Gecko
Guest





PostPosted: Sat May 31, 2008 5:22 pm    Post subject: Reply with quote

i actually never savely remove usb-sticks, so i never experienced this. Twisted Evil
althogh the WM_DEVICECHANGE message ( aka the link provided by Zippo()) ) looks promising, there is an maybe easier workaround:

1. the script on the usb-stick, that is launched, just copies another script to a temp-dir on the harddrive and launches this. And it exits right after that.
2. the script on the temp-dir checks the existance of the usb-stick. If the stick is removed, it will exit and delete itself (via a batch-file, if necessary).
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group