怎么判断程序是否已经设置了开机启动?
我设置了一个程序,里面有两个按钮,实现了开机启动,下面这两段代码。
'开机启动Private Sub command1_Click()Dim wSet w = CreateObject("wscript.shell")w.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe"MsgBox "设置自启动成功!"End Sub'取消开机启动Private Sub command2_Click()Dim wSet w = CreateObject("wscript.shell")w.regdelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXENameMsgBox "取消自启动成功!"End Sub
Option ExplicitPrivate WshShellPrivate Sub Form_Load() Set WshShell = CreateObject("wscript.shell") If funKeyExist Then Check1.Value = 1 Else Check1.Value = 0 End IfEnd SubPrivate Sub Form_Unload(Cancel As Integer) If Check1.Value = 1 And Not funKeyExist Then WshShell.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe" MsgBox "设置自启动成功!" End If If Check1.Value = 0 And funKeyExist Then WshShell.regdelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName MsgBox "取消自启动成功!" End IfEnd SubPrivate Function funKeyExist() As Boolean '//存在返回true,否则返回false On Error Resume Next WshShell.regread "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName '//如果不存在读取会有错 If Err Then funKeyExist = False Else funKeyExist = True End IfEnd Function