通过设置和读取注册表可以实现我们的应用程序随Windows的启动即可执行的功能下面就是实现的代码
Formvb Imports MicrosoftWinRegistry Public Class Form Inherits SystemWindowsFormsForm #Region Windows 窗体设计器生成的代码 Public Sub New() MyBaseNew() 该调用是 Windows 窗体设计器所必需的 InitializeComponent() 在 InitializeComponent() 调用之后添加任何初始化 End Sub 窗体重写处置以清理组件列表 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then componentsDispose() End If End If MyBaseDispose(disposing) End Sub Windows 窗体设计器所必需的 Private components As SystemComponentModelIContainer 注意以下过程是 Windows 窗体设计器所必需的 可以使用 Windows 窗体设计器修改此过程 不要使用代码编辑器修改它 Friend WithEvents CheckBox As SystemWindowsFormsCheckBox Friend WithEvents btnSave As SystemWindowsFormsButton <SystemDiagnosticsDebuggerStepThrough()> Private Sub InitializeComponent() MeCheckBox = New SystemWindowsFormsCheckBox() MebtnSave = New SystemWindowsFormsButton() MeSuspendLayout() CheckBox MeCheckBoxBackColor = SystemDrawingSystemColorsControl MeCheckBoxChecked = True MeCheckBoxCheckState = SystemWindowsFormsCheckStateChecked MeCheckBoxForeColor = SystemDrawingSystemColorsControlText MeCheckBoxImeMode = SystemWindowsFormsImeModeNoControl MeCheckBoxName = CheckBox MeCheckBoxRightToLeft = SystemWindowsFormsRightToLeftYes MeCheckBoxSize = New SystemDrawingSize( ) MeCheckBoxTabIndex = MeCheckBoxText = Windows开机即运行 MeCheckBoxTextAlign = SystemDrawingContentAlignmentMiddleRight btnSave MebtnSaveBackColor = SystemDrawingSystemColorsControl MebtnSaveFont = New SystemDrawingFont(宋体 !) MebtnSaveForeColor = SystemDrawingSystemColorsControlText MebtnSaveImeMode = SystemWindowsFormsImeModeNoControl MebtnSaveLocation = New SystemDrawingPoint( ) MebtnSaveName = btnSave MebtnSaveSize = New SystemDrawingSize( ) MebtnSaveTabIndex = MebtnSaveText = 保存设置 Form MeAutoScaleBaseSize = New SystemDrawingSize( ) MeClientSize = New SystemDrawingSize( ) MeControlsAddRange(New SystemWindowsFormsControl() {MebtnSave MeCheckBox}) MeFormBorderStyle = SystemWindowsFormsFormBorderStyleFixedToolWindow MeName = Form MeStartPosition = SystemWindowsFormsFormStartPositionCenterScreen MeText = Windows开机即运行 MeResumeLayout(False) End Sub #End Region Dim Reg As MicrosoftWinRegistryKey Private Sub InitVar() If btnSaveVisible = True Then End If Reg = CurrentUserOpenSubKey(Software\Microsoft\Windows\CurrentVersion\Run True) If RegGetValue(MengXianHui) <> Then CheckBoxChecked = True Else CheckBoxChecked = False End If End Sub Private Sub SaveSettings() If CheckBoxChecked = True Then Reg = CurrentUserOpenSubKey(Software\Microsoft\Windows\CurrentVersion\Run True) RegSetValue(MengXianHui ApplicationExecutablePath) Else Reg = CurrentUserOpenSubKey(Software\Microsoft\Windows\CurrentVersion\Run True) RegSetValue(MengXianHui ) End If InitVar() MessageBoxShow(您已经设置了请重新启动计算机看效果 提示 _ MessageBoxButtonsOK MessageBoxIconInformation) If CheckBoxChecked = True Then MeDispose(True) End If End Sub Private Sub btnSave_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) _ Handles btnSaveClick SaveSettings() End Sub End Class |