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
插入后,出现了消息框。现在,要运行我替换的文件
MsgBox(4096, "Info", "My Drive has been Inserted, Backup My Files!")
通过
Run ("F:\path\to\my\file.cmd")
但要更改的内容可以在分配不同于file.cmd
的驱动器号的计算机上运行F:
吗?
答案 0 :(得分: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文件执行了某些操作。