Jump to content

eject USB HDD


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...