熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> ASP編程 >> 正文

如何編寫隨Windows啟動運行的程序

2013-11-15 12:49:30  來源: ASP編程 

  通過設置和讀取注冊表可以實現我們的應用程序隨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 


From:http://tw.wingwit.com/Article/program/ASP/201311/21708.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.