Hi Leute,
so habe nen programm geschrieben das mir einen USB Stick dismountet nachdem ein anderes Programm ihm den Parameter mit dem Laufwerkbuchstaben übergeben hat.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
If @OSArch = "X64" Then
_ejectUSB64()
EndIf
If @OSArch = "X86" Then
_ejectUSB32()
EndIf
_SelfDelete()
[/autoit] [autoit][/autoit] [autoit]Func _ejectUSB32($drive = '')
Local $path = @TempDir & '\EjectMedia.exe'
If $drive = '' Or $drive = Default Then $drive = StringLeft(@ScriptDir, 2)
If $cmdLine[0] = 1 And ($cmdLine[1] = '-?' Or $cmdLine[1] = '/?') Then
MsgBox(64, 'Information', 'Parameter : (Drive) e.g. : E:', 5)
Exit (0)
EndIf
If $cmdLine[0] = 1 Then $drive = $cmdLine[1]
FileInstall('32\EjectMedia.exe', $path, 1)
If Not FileExists($drive) Then Return -1
If Not FileExists($path) Then Return -2
Run($path & ' ' & $drive & ' -l -f -s -w:1000', @TempDir, @SW_HIDE)
$Form2 = GUICreate("Please wait...", 501, 120, -1, -1,0)
$Progress1 = GUICtrlCreateProgress(39, 53, 422, 17, BitOR($PBS_SMOOTH,$PBS_MARQUEE))
$Label1 = GUICtrlCreateLabel("Dismounting USB Drive...", 39, 19, 124, 17)
GUICtrlSendMsg($progress1, 0x040A, 1, 35)
GUISetState()
Do
Until ProcessWaitClose("EjectMedia.exe")
Return 1
EndFunc ;==>_ejectUSB32
Func _ejectUSB64($drive = '')
Local $path = @TempDir & '\EjectMedia.exe'
If $drive = '' Or $drive = Default Then $drive = StringLeft(@ScriptDir, 2)
If $cmdLine[0] = 1 And ($cmdLine[1] = '-?' Or $cmdLine[1] = '/?') Then
MsgBox(64, 'Information', 'Parameter : (Drive) e.g. : E:', 5)
Exit (0)
EndIf
If $cmdLine[0] = 1 Then $drive = $cmdLine[1]
FileInstall('64\EjectMedia.exe', $path, 1)
If Not FileExists($drive) Then Return -1
If Not FileExists($path) Then Return -2
Run($path & ' ' & $drive & ' -l -f -s -w:1000', @TempDir, @SW_HIDE)
$Form2 = GUICreate("Please wait...", 501, 120, -1, -1,0)
$Progress1 = GUICtrlCreateProgress(39, 53, 422, 17, BitOR($PBS_SMOOTH,$PBS_MARQUEE))
$Label1 = GUICtrlCreateLabel("Dismounting USB Drive...", 39, 19, 124, 17)
GUICtrlSendMsg($progress1, 0x040A, 1, 35)
GUISetState()
Do
Until ProcessWaitClose("EjectMedia.exe")
Return 1
EndFunc ;==>_ejectUSB64
Func _SelfDelete($iDelay = 0)
Local $sCmdFile
FileDelete(@TempDir & "\scratch.bat")
$sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
& ':loop' & @CRLF _
& 'del "' & @ScriptFullPath & '"' & @CRLF _
& 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
& 'del ' & @TempDir & '\scratch.bat'
FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc
Sooooo jetzt hab ich es getestet auf nem 64bit Windows 7, funktioniert.
Dann auf einem 32bit Win-XP, funktioniert.
Dann auf einem anderen 32bit Win-XP, funktioniert nicht. Folgende Fehlermeldung:
[Blockierte Grafik: http://www.bilderload.com/bild/89264/errorHLZC6.jpg]
Gut, dann habe ich mal gegugt mit @OSArch und @CPUArch. Der zweite Rechner hat nähmlich ein 64bit CPU aber nen 32bit System.
Jetzt die Frage: Kann es sein das es ein Problem gibt beim ausführen der 32bit exe von EjectMedia ? Immerhin ratert er erstmal 2 sekunden und dann kommt die meldung. Wenn ich jetzt aber die 64bit exe starte dann klappts von anfang an garnicht.
Grüße cashy ![]()