回复 4# lixiaolong
你的代码中有这句 $iniFile = "TrayMenu.ini"
这句不随系统启动就可以打开,但随系统启动就打不开,就是找不到文件
主要把它改为 $iniFile = @ScriptDir & "\TrayMenu.ini"` ;指定完整路径
或者
FileInstall("TrayMenu.ini",@TempDir & "\TrayMenu.ini", 1)
$iniFile = @TempDir & "\TrayMenu.ini"
这样就可以打开了。;---------------------------------------------------------程序源码------------------------------------------------
#include <Constants.au3>
#include <File.au3>
$iniFile = @ScriptDir & "\TrayMenu.ini"
;FileInstall("TrayMenu.ini",@TempDir & "\TrayMenu.ini", 1)
;$iniFile = @TempDir & "\TrayMenu.ini"
$varTrayMenuList = IniReadSection($iniFile, "TrayMenu")
$varTrayItemList = IniReadSection($iniFile, "TrayItem")
$tempFile = _TempFile()
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetClick(16)
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
Exit
Else
For $i = 1 To $varTrayMenuList[0][0]
$menu = TrayCreateMenu($varTrayMenuList[$i][1])
For $j = 1 To $varTrayItemList[0][0]
If ($varTrayItemList[$j][0] == $varTrayMenuList[$i][0]) Then
$temp = StringSplit($varTrayItemList[$j][1], ";")
$tid = TrayCreateItem($temp[1], $menu)
TrayItemSetOnEvent($tid, "RunApp")
IniWrite($tempFile, "MenuKey", $tid, $temp[2])
EndIf
Next
Next
EndIf
$varMenuKeyList = IniReadSection($tempFile, "MenuKey")
TrayCreateItem("")
Local $sRegPath = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
$settingsit = TrayCreateMenu("随系统启动")
$Yes = TrayCreateItem("启动", $settingsit)
TrayItemSetOnEvent($Yes, "Yes")
$No = TrayCreateItem("关闭", $settingsit)
TrayItemSetOnEvent($No, "No")
$exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "ExitFun")
TraySetState()
If RegRead($sRegPath, @ScriptName) <> '' Then
TrayItemSetState($Yes, 1)
Else
TrayItemSetState($No, 1)
EndIf
While 1
Sleep(500)
WEnd
Exit
Func RunApp()
For $k = 1 To $varMenuKeyList[0][0]
If ($varMenuKeyList[$k][0] == @TRAY_ID) Then
RunWait($varMenuKeyList[$k][1])
EndIf
Next
EndFunc ;==>RunApp
Func ExitFun()
Exit
EndFunc ;==>ExitFun
Func Yes()
RegWrite($sRegPath, @ScriptName, 'REG_SZ', '' & @ScriptFullPath)
TrayItemSetState($No, 4)
;RegWrite($sRegPath, @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '" /AUTO')
MsgBox(0, '状态:', '本程序将会随系统启动')
EndFunc ;==>Yes
Func No()
RegDelete($sRegPath, @ScriptName)
TrayItemSetState($Yes, 4)
MsgBox(0, '状态:', '本程序卸载随系统启动')
EndFunc ;==>No
;---------------------------------------------------------程序源码------------------------------------------------
;;--------------------------------------------------------配置文件TrayMenu.ini------------------------------------
;
;[TrayMenu]
;1=工具菜单
;2=程序相关
;[TrayItem]
;1=测试1;AUTOIT.exe
;1=测试2;Tools\Scite\Scite.exe
;2=测试3;001\AUTOIT.exe
;
;---------------------------------------------------------配置文件TrayMenu.ini------------------------------------
|