AutoHotkey Community

It is currently May 26th, 2012, 7:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: May 30th, 2008, 10:31 am 
Offline

Joined: April 16th, 2008, 7:55 am
Posts: 43
Is it possible to exit several scripts by unplugging a USB stlck safely?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2008, 1:17 pm 
Yes, e.g. with IfExist


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 6:18 am 
Offline

Joined: April 16th, 2008, 7:55 am
Posts: 43
I am not very good at this so please could you work it out for me?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 8:40 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 11:24 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 12:39 pm 
http://msdn.microsoft.com/en-us/library ... 85%29.aspx might be the way to go.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 31st, 2008, 5:22 pm 
i actually never savely remove usb-sticks, so i never experienced this. :twisted:
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).


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, chenhaiyang, kkkddd1, Leef_me, Tilter_of_Windmills, tomL and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group