16,717
社区成员
发帖
与我相关
我的任务
分享
Public Function RunWhenStart(ByVal Started As Boolean, Optional ByVal IsSetValue As Boolean = True) As Boolean
Dim State As Boolean = False
Dim HKLM As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim Run As Microsoft.Win32.RegistryKey = HKLM.CreateSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
Try
If IsSetValue Then
If Started Then
Run.SetValue("Test", Application.ExecutablePath)
Else
Run.DeleteValue("Test")
End If
Else
State = (Run.GetValue("Test", "") <> "")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
Finally
HKLM.Close()
End Try
Return State
End Function