【已解决】按间隔时间循环读取.ini文件
本帖最后由 hljkwan 于 2021-11-12 13:28 编辑#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $aArray = DriveGetDrive($DT_REMOVABLE)
If @error Then
; An error occurred when retrieving the drives.
MsgBox($MB_SYSTEMMODAL, "温馨提示", "未发现ini文件")
Else
EndIf
For $i = 1 to $aArray
$aArray = IniRead($aArray[$i] & "\au3.ini", "key", "code", "")
if $aArray <> 0 Then
$keycode = $aArray
EndIf
Next
if $keycode = 1234567890 Then
; Show all the drives found and convert the drive letter to uppercase.
; MsgBox($MB_SYSTEMMODAL, "提示", "Drive " & $i & "/" & $aArray & ":" & @CRLF & StringUpper($aArray[$i]))
Run("C:\Everything.exe")
Else
EndIf
新建au3.ini文件,打开输入
code=1234567890
将Everything放入C盘根目录(附件已上传)外部下载链接(http://www.itmop.com/downinfo/16205.html)
将au3.ini拷贝进U盘,将U盘插入电脑,运行代码,Everything打开,当拔掉U盘,Everything任然处于打开状态
怎么写一个循环读取命令,比如10秒读取一次U盘中的au3.ini.ini文件,当读取不到时,自动关闭Everything。
求大神指点一下
检测U盘如果检测到U盘拔掉那么退出 #include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("纯AU3获取U盘信息 by sh1536", 800, 240)
$ListView1 = GUICtrlCreateListView("磁盘号|盘符|卷标|内部名称|容量|VID|PID|序列号", 0, 0, 800, 240)
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUICtrlSendMsg(-1, 0x101E, 1, 40)
GUICtrlSendMsg(-1, 0x101E, 3, 250)
GUICtrlSendMsg(-1, 0x101E, 7, 240)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
updq()
GUIRegisterMsg(0x0219, '_USB_Message')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _USB_Message($hWnd, $Msg, $wParam, $lParam);检测U盘拔插(此源码来源3mile前辈,感谢)
Switch $wParam
Case 0x8000;设备插入
Local $_DEV_BROADCAST_HDR = DllStructCreate("int dbch_size; int dbch_devicetype; int dbch_reserved;", $lParam)
If DllStructGetData($_DEV_BROADCAST_HDR, "dbch_devicetype") = 2 Then
Local Const $DEV_BROADCAST_VOLUME = DllStructCreate("int dbcv_size; int dbcv_devicetype; int dbcv_reserved; int dbcv_unitmask; word dbcv_flags", $lParam)
Local Const $unitMask = DllStructGetData($DEV_BROADCAST_VOLUME, "dbcv_unitmask")
$drivers=_get_driverflag($unitMask);获取拔插设备的盘符
$aArray = IniRead($drivers & "\au3.ini", "key", "code", "")
if $aArray <> 0 Then
$keycode = $aArray
EndIf
if $keycode = 1234567890 Then
Run("I:\Everything\Everything.exe")
EndIf
;~ If DriveGetType($drivers&"")="Removable" then _GetUSBDisk();移动硬盘是DRIVE_FIXED,U盘是DRIVE_REMOVABLE
EndIf
Case 0x8004;设备移除
ProcessClose("Everything.exe")
EndSwitch
EndFunc ;==>_USB_Message
Func _get_driverflag($unitMask);搭配_USB_Message()使用
Local $Count = 0
Local $Pom = Round($unitMask / 2)
While $Pom > 0
$Pom = BitShift($Pom, 1)
$Count += 1
WEnd
If $Count >= 1 And $Count <= 26 Then
Return Chr(65 + $Count) & ":"
Else
Return '?'
EndIf
EndFunc ;==>_get_driverflag
Func updq()
Local $aArray = DriveGetDrive($DT_REMOVABLE)
For $i = 1 to $aArray
$aArray = IniRead($aArray[$i] & "\au3.ini", "key", "code", "")
if $aArray <> 0 Then
$keycode = $aArray
EndIf
Next
if $keycode = 1234567890 Then
Run("I:\Everything\Everything.exe")
EndIf
EndFunc
拔掉U盘自己关闭 xz00311 发表于 2021-11-12 10:02
拔掉U盘自己关闭
厉害了我的哥,感谢! #include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("插拔隨身碟檢測特定檔案並執行", 200, 140)
;GUISetState(@SW_SHOW)
GUISetState(@SW_HIDE)
updq()
GUIRegisterMsg(0x0219, '_USB_Message') ;WM_DEVICECHANGE
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _USB_Message($hWnd, $Msg, $wParam, $lParam) ;檢測隨身碟插拔(此源碼來源3mile,感謝)
MsgBox(0,"","隨身碟插拔通知:" & $wParam)
Switch $wParam
Case 0x0007 ;設備插拔通知代碼,好像不同電腦有不同代碼,依情況修改
updq()
EndSwitch
EndFunc ;==>_USB_Message
Func updq()
Local $aTemp, $keycode = ""
Local $aArray = DriveGetDrive($DT_REMOVABLE) ;取出隨身碟數量及代號
;MsgBox(0,"",$aArray)
For $i = 1 to $aArray
;MsgBox(0,"",$aArray[$i])
$aTemp = IniRead($aArray[$i] & "\au3.ini", "key", "code", "") ; 自行在隨身碟跟目錄下建立 au3.ini內容為,code="1234567890"
;MsgBox(0,"",$aTemp)
if $aTemp <> "" Then
$keycode = $aTemp
EndIf
Next
If $keycode = 1234567890 Then
MsgBox(0,"","符合code值,後面可以自行加入功能") ;後面可依需求增加功能
Else
MsgBox(0,"","不符合code值,後面可以自行加入功能") ;後面可依需求增加功能
EndIf
EndFunc yohoboy 发表于 2021-11-13 01:13
#include
#include
#include
感谢~~感谢!
页:
[1]