Jump to content
Sign in to follow this  
hot202

eject USB HDD

Recommended Posts

hot202

hi im trying to find away to eject my USB hdd on win7 but all the scripts out there dont seem to work. Dose any1 know how to get it working for win7?

Share this post


Link to post
Share on other sites
Xenobiologist

Have you tried devcon.exe von commandline shell (DOSBOX) ?

If that works, you can automate it.


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
hot202

nah i didnt know what that was and where to get it and how to use it.

Share this post


Link to post
Share on other sites
trancexx

Search forums with this DeviceIoControl trancexx


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
99ojo

Hi,

you have to download Windows Driver Kit 7.1.0 ( 610 MB ) to get a running version of devcon.exe under Win 7.

http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx

After extracting you will find suitable version under

"%InstDrv%\WinDDK\7600.16385.0\Tools\Devcon"

;-))

Stefan

Share this post


Link to post
Share on other sites
hot202

so i will have to have Windows Driver Kit 7.1.0 installed on every computer that i want to eject the usb?

Share this post


Link to post
Share on other sites
wraithdu

Tried my UDF HERE yet? I just updated it to make sure it works on x64.

Share this post


Link to post
Share on other sites
hot202

I cant seem to get it working on my win7 computer using your example

in the console i keep getting Ejecting drive <G:> - False

edit:

is there anyway to eject the drive if the script is ran from that drive?

Edited by hot202

Share this post


Link to post
Share on other sites
99ojo

so i will have to have Windows Driver Kit 7.1.0 installed on every computer that i want to eject the usb?

Hi,

no. you have to install it once to get the devcon.exe for Win7 32 bit and Win7 64 bit.

In your code, you might have to query OS build to run the suitable devcon.exe.

Here sample code to query usb stick, you have to declare $workdir by yourself:

$strrun = $workdir & "\devcon find = WPD USB\VID* >" & $workdir & "\usbdev.txt"
RunWait (@ComSpec & " /c " & $strrun, $workdir, @SW_HIDE)
_FileReadToArray ($workdir & "\usbdev.txt", $usbdev)
FileDelete ($workdir & "\usbdev.txt")

and deactivate USB Stick on exit, using array $usbdev from above:

Func _Exit ()
    ;Sind USB Drives vorhanden ( are there USB Sticks )
    If IsArray ($usbdev) Then
        For $x = 1 to UBound ($usbdev) - 1
            If StringInStr ($usbdev [$x], "USB-Massenspeicher") <> 0 Then
                $crecords = StringSplit ($usbdev [$x], "\")
                ;Entferne USB Drives zum sicheren entfernern (disable USB Stick for save removal)
                RunWait (@ComSpec & " /c " & $workdir & "\devcon remove """ & $crecords [1] & "\" & $crecords [2] & """")
            EndIf
        Next
    EndIf
    ;Ende (Exit)
    Exit
EndFunc

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
Yashied
wraithdu

edit:

is there anyway to eject the drive if the script is ran from that drive?

Of course NOT. How can you expect to safely remove a usb drive if you have an application running from that very drive?

Share this post


Link to post
Share on other sites
hot202

Thought maybe there would be away to close the script but still eject the usb drive.

Share this post


Link to post
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
Sign in to follow this  

×