#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("开机启动设置工具", 600, 100, -1, -1)
$Input1 = GUICtrlCreateInput("C:\WINDOWS\system32\cmd.exe /k ipconfig /all", 24, 24, 509, 21)
$Button1 = GUICtrlCreateButton("浏览", 540, 24, 50, 21)
$Button2 = GUICtrlCreateButton("设置启动运行", 100, 60, 100, 25)
$Button3 = GUICtrlCreateButton("取消启动运行", 250, 60, 100, 25)
$Button4 = GUICtrlCreateButton("退出", 400, 60, 60, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $Button4
exit
case $Button1
$var = FileOpenDialog("选择启动运行的程序", "", "可执行文件(*.exe;*.cmd;*.bat;*.vbs)")
If @error Then
Else
GUICtrlSetData($Input1,$var)
EndIf
case $Button2
$run1 = GUICtrlRead($Input1)
$run2 = StringTrimLeft($run1,StringInStr($run1, "",0,-1))
$run3 = StringLeft($run2,StringInStr($run2, ".",0,-1)-1)
if RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$run3) = $run1 then
msgbox(48,"错误","此启动项已经存在,请勿重复设置!",3)
else
RegWrite("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$run3, "REG_SZ", $run1)
if RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$run3) <> $run1 then msgbox(16,"失败","添加启动项失败!请检查用户和注册表权限!",3)
endif
case $Button3
$run1 = GUICtrlRead($Input1)
$run2 = StringTrimLeft($run1,StringInStr($run1, "",0,-1))
$run3 = StringLeft($run2,StringInStr($run2, ".",0,-1)-1)
if RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$run3) = $run1 then
RegDelete("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$run3)
if RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$run3) = $run1 then msgbox(16,"失败","删除启动项失败!请检查用户和注册表权限!",3)
else
msgbox(48,"错误","此启动项不存在!")
endif
EndSwitch
WEnd