2016-02-07 43 views
-1

Windows中禁用了自動運行。我正在尋找替代品。我得到這個AutoIt腳本:自動運行可移動驅動器

$DBT_DEVICEARRIVAL = "0x00008000" 
$WM_DEVICECHANGE = 0x0219 

GUICreate("") 
GUIRegisterMsg($WM_DEVICECHANGE , "MyFunc") 

Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam) 
     If $WParam == $DBT_DEVICEARRIVAL Then 
      MsgBox(4096, "Info", "My Drive has been Inserted, Backup My Files!") 
     EndIf 
EndFunc 

While 1 
     $GuiMsg = GUIGetMsg() 
WEnd 

不久,插入消息框。現在,運行文件我用

Run ("F:\path\to\my\file.cmd") 

更換

MsgBox(4096, "Info", "My Drive has been Inserted, Backup My Files!") 

但要改變什麼,所以file.cmd可以在分配比F:不同的驅動器號的計算機上運行?

+2

可能的重複[自動腳本運行USB時安裝](http://stackoverflow.com/questions/35252893/autoit-script-to-run-when-usb-is-mounted) – Milos

回答

0

我搜索了這個代碼在一個可移動設備(SD卡)的一些WAVE-文件:

#include <Array.au3> 

; Register search function 
Global $DBT_DEVICEARRIVAL = "0x00008000" 
Global $WM_DEVICECHANGE = 0x0219 
Global $drives = DriveGetDrive("REMOVABLE") 
GUIRegisterMsg($WM_DEVICECHANGE, "searchOnSD") 

; check all already known removable devices 
If UBound($drives) > 0 Then 
    For $drive In $drives 
     If StringRegExp($drive, "^[[:alpha:]]:$") Then check($drive) 
    Next 
EndIf 

; search for WAV-file on SD-Card 
Func searchOnSD($hWndGUI, $MsgID, $WParam, $LParam) 
    If $WParam == $DBT_DEVICEARRIVAL Then 
     $newDrives = DriveGetDrive("REMOVABLE") 
     $drive = $newDrives 
     For $i = 0 To UBound($drives) - 2 
      _ArrayDelete($drive, 0) 
     Next 
     If UBound($drive) > 0 Then 
      $drive = $drive[0] 
      If StringRegExp($drive, "^[[:alpha:]]:$") Then 
       ConsoleWrite("new removable (" & $drive & ") found." & @CR) 
       check($drive) 
      EndIf 
     EndIf 
    EndIf 
    $drives = DriveGetDrive("REMOVABLE") 
EndFunc ;==>searchOnSD 

check($drive)功能,那麼我估計DriveStatus($drive) == "READY" And FileExists($wavFile)後進行一些與WAVE文件。