| View previous topic :: View next topic |
| Author |
Message |
Jag02
Joined: 16 Apr 2008 Posts: 39
|
Posted: Fri May 30, 2008 10:31 am Post subject: Is it possible to exit a script by unplugging a USB stlck? |
|
|
| Is it possible to exit several scripts by unplugging a USB stlck safely? |
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Fri May 30, 2008 1:17 pm Post subject: |
|
|
| Yes, e.g. with IfExist |
|
| Back to top |
|
 |
Jag02
Joined: 16 Apr 2008 Posts: 39
|
Posted: Sat May 31, 2008 6:18 am Post subject: |
|
|
| I am not very good at this so please could you work it out for me? |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1020 Location: The Interwebs
|
Posted: Sat May 31, 2008 8:40 am Post subject: |
|
|
| 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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2605 Location: Australia, Qld
|
Posted: Sat May 31, 2008 11:24 am Post subject: |
|
|
| 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 |
|
 |
Zippo() Guest
|
|
| Back to top |
|
 |
Z Gecko Guest
|
Posted: Sat May 31, 2008 5:22 pm Post subject: |
|
|
i actually never savely remove usb-sticks, so i never experienced this.
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 |
|
 |
|