Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

RemUMS - Safely Remove USB Mass Storage Drive


  • Please log in to reply
3 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005


Posted Image
The latest version RemUMS v1.0 is a complete rewrite and tested in Windows XP SP3 & Windows 7


Given a drive letter, RemUMS will locate the Device-ID of USB/Flash Drive and Eject it.

Features ( 1.0.0.0 ) :

[*:uq92ty4j]Verbose. Outputs info to console or MessageBox
[*:uq92ty4j]Tested fine in:
[*:uq92ty4j]Win XP 32 bit SP3
[*:uq92ty4j]Win7 Home Basic x64
[*:uq92ty4j]Win7 Home Premium x64[*:uq92ty4j]Fully based on SetupAPI DLL. Calls CM_Request_Device_Eject() to eject drive.
[*:uq92ty4j]Small footprint 64 KiB only, low processor usage.
[*:uq92ty4j]ProcessWaitClose to aid AHK automation.


Author: SKAN ( Suresh Kumar A N ).
License: PD-Self
_________________________________________________________

FileName: RemUMS.exe ( Remove USB Mass Storage Drive )
FileDate: 05-Sep-2012
FileType: 32bit Console
FileVersion: 1.0.0.0 ( MD5: eb8f8413c6b0699966ca97b2f5890847 )
FileSize: 64 KiB
AV Scan : VirusTotal Results | Virusscan.Jotti

http://dl.dropbox.co...v1-0/RemUMS.ico <- RemUMS.ico 1.6 KiB ( 48x48 4bit )
_________________________________________________________
^ Icon by ~dAKirby309 @ deviantart.com


Posted Image


Usage & Examples:

Simple usage:

RemUMS "<DrivePath>"
( only the first character of DrivePath is considered. )

RemUMS D:\
RemUMS D:
RemUMS D

If you are passing Longpath, wrap the DrivePath within double quotes, like: Run, RemUMS "%A_AhkPath%"

Advanced Usage:

RemUMS <DrivePath> <PID> <PID_Timeout> <MsgBox_Timeout>


[*:uq92ty4j]PID - If you pass the PID of a running process, RemUMS will wait for the process to close or PID_Timeout expires - whichever occurs first.
[*:uq92ty4j]PID_Timeout - Wait period in milliseconds. If not specified, RemUMS will wait 10 minutes for process to close then proceed to Eject.
If you pass 0 for PID, then RemUMS will unconditionally sleep for the Timeout specified.
[*:uq92ty4j]MsgBox_Timeout - Wait period in milliseconds. By default error/info is written to console.
If MsgBox_Timeout is passed, output is shown in screen via MessageBox and is auto-dismissed when timeout expires.
Pass -1, if you do not want the MessageBox to auto-dismiss.
One advantage of using this parameter is that - you will be prompted with a Retry dialog if Drive ejection was unsuccessful.

Posted Image
note: the Retry dialog is never auto-dismissed!

Realworld example:

I have dedicated an USB flash drive for my AutoHotkey application. It self-ejects on GuiClose as follows:

GuiClose:
 OnExit
 If FileExist( [color=#FF8000]RemUMS[/color] ) {
   FileCopy, %RemUMS%, %A_Temp%, 1
   Run, %A_Temp%\RemUMS.exe "%A_ScriptDir%" %[color=#FF8000]PID[/color]% 10000 3000, %A_Temp%, Hide
 }
 ExitApp
Return
[color=#008040]; RemUMS and PID are initialized in auto-execute section[/color]

Advanced call examples:

RemUMS D: 0 1000 - No ProcessWaitClose, but sleep for 1000ms before trying anything.
RemUMS D: %PID% -1 - ProcessWaitClose or 10 minutes, whichever occurs first and then try Ejecting.
RemUMS D: 0 0 -1 - No ProcessWaitClose or any auto-dismiss timeout. Attempt to Eject the drive & Show me Error/Result Dialog.

Errorlevel:

When drive-ejection is successful, errorlevel will be set to zero and RemUMS will print the Device-ID that was ejected.
If MsgBox_Timeout is specified, then a dialog will be displayed:

Posted Image

[*:uq92ty4j]100 : No parameters passed. Usage suggestion will be printed
[*:uq92ty4j]101 : Invalid Drive!.. Volume is inaccessible
[*:uq92ty4j]102 : Drive is not a valid USB Mass Storage Device ( CD-ROM etc )
[*:uq92ty4j]103 : Error retrieving Device Number
[*:uq92ty4j]104 : Device enumeration failed
[*:uq92ty4j]105 : Machine does not have Storage drives ( impossible )
[*:uq92ty4j]106 : Drive letter does not match any Storage class device ( impossible )
Above are STOP errors and program will exit immediately... If you specified MsgBox_Timeout, error dialog will be shown before exiting:

Posted Image

If Errorlevel is lesser than 100, it would have been set by CM_Request_Device_Eject() as follows:

PNP_VETO_TYPE

[*:uq92ty4j]PNP_VetoTypeUnknown = 1
The specified operation was rejected for an unknown reason.
[*:uq92ty4j]PNP_VetoLegacyDevice = 2
The device does not support the specified PnP operation.
[*:uq92ty4j]PNP_VetoPendingClose = 3
The specified operation cannot be completed because of a pending close operation.
[*:uq92ty4j]PNP_VetoWindowsApp = 4
A Microsoft Win32 application vetoed the specified operation.
[*:uq92ty4j]PNP_VetoWindowsService = 5
A Win32 service vetoed the specified operation.
[*:uq92ty4j]PNP_VetoOutstandingOpen = 6
The requested operation was rejected because of outstanding open handles.

[*:uq92ty4j]PNP_VetoDevice = 7
The device supports the specified operation, but the device rejected the operation.
[*:uq92ty4j]PNP_VetoDriver = 8
The driver supports the specified operation, but the driver rejected the operation.
[*:uq92ty4j]PNP_VetoIllegalDeviceRequest = 9
The device does not support the specified operation.
[*:uq92ty4j]PNP_VetoInsufficientPower = 10
There is insufficient power to perform the requested operation.
[*:uq92ty4j]PNP_VetoNonDisableable = 11
The device cannot be disabled.
[*:uq92ty4j]PNP_VetoLegacyDriver = 12
The driver does not support the specified PnP operation.
[*:uq92ty4j]PNP_VetoInsufficientRights = 13
The caller has insufficient privileges to complete the operation.
For PNP_ errors, if MsgBox_Timeout was specified, you will be prompted with Retry dialog

Posted Image
note: the Retry dialog is never auto-dismissed!
[/list]
kWo4Lk1.png

joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Nov 02 2019 08:38 PM
  • Joined: 20 May 2012

Awesome.. But dead link??

whoops sorry it works


Why ahkscript.org? - autohotkey.com is outdated

Scoox
  • Members
  • 194 posts
  • Last active: Jun 09 2017 03:34 AM
  • Joined: 28 Nov 2010
So where is the download link or the script for this?

RegJump() - Jump to registry path in Regedit

HoverScroll() - HoverScroll() - Scroll controls without focus


joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Nov 02 2019 08:38 PM
  • Joined: 20 May 2012
http://tinyurl.com/R...v1-0/RemUMS.exe ;)
Why ahkscript.org? - autohotkey.com is outdated