自动运行的可移动驱动器 [英] Autorun removable drive

查看:81
本文介绍了自动运行的可移动驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows中禁用了自动运行。我正在寻找替代方案。我得到了这个AutoIt脚本:

Autorun was disabled in Windows. I am looking for an alternative. I got this AutoIt script :

 $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

插入后不久,消息框出现。现在,要运行我替换的文件

Soon as plugged in, the message box appeared. Now, to run a file I replaced

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

by

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

但要更改的内容,因此 file.cmd 可以在分配了不同于 F的驱动器号的计算机上运行:

But what to change so file.cmd can be run on computers that assign a drive letter different than F:?

推荐答案

我使用以下代码在可移动设备(SD卡)上搜索了一些WAVE文件:

I searched for some WAVE-files on a Removable Device (SD-Card) with this code:

#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和FileExists($ wavFile)

这篇关于自动运行的可移动驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆