cStartUp Auto-start Management Component
Overview
cStartUp is an auto-start management component provided by the VBMAN framework, used to manage Windows system registry startup items. Supports adding, removing, and querying startup items with startup parameters.
Features
- Toggle Mode - Auto determines whether to add or remove startup item
- Parameter Support - Can pass command line parameters to startup program
- Dual Path Mode - Supports passing App object or string path
- Global Access - Quick access via
VBMAN.StartUp
Quick Start
Check Current Auto-start Status
vb
Private Sub Form_Load()
' Set menu check state
MenuStartUp.Checked = VBMAN.StartUp.Has("my-app-name")
End SubToggle Auto-start
vb
Private Sub MenuStartUp_Click()
' Toggle auto-determines: add if not exists, remove if exists
If VBMAN.StartUp.Toggle("my-app-name", App) = True Then
' Toggle successful, update menu state
MenuStartUp.Checked = VBMAN.StartUp.Has("my-app-name")
VBMAN.Toast.Show IIf(MenuStartUp.Checked, "Set auto-start success", "Cancel auto-start success")
Else
' Toggle failed, show error
VBMAN.Toast.Show "Auto-start setting failed: " & VBMAN.StartUp.LastError
End If
End SubRegistry Location
Component operates on the following Windows registry location:
HKCU\Software\Microsoft\Windows\CurrentVersion\RunNote: HKCU means current user, the set startup only applies to current user.
Complete Example
vb
'===============================================
' Auto-start Management Complete Example
'===============================================
Private Sub Form_Load()
' Initialize menu state
UpdateStartUpMenu()
End Sub
' Click auto-start menu
Private Sub MenuStartUp_Click()
ToggleStartUp
End Sub
' Toggle auto-start status
Private Sub ToggleStartUp()
Dim AppName As String
AppName = "my-application"
' Method 1: Pass App object (recommended)
If VBMAN.StartUp.Toggle(AppName, App) Then
UpdateStartUpMenu()
ShowToggleResult
Else
MsgBox "Setting failed: " & VBMAN.StartUp.LastError, vbCritical
End If
End Sub
' Update menu check state
Private Sub UpdateStartUpMenu()
MenuStartUp.Checked = VBMAN.StartUp.Has("my-application")
End Sub
' Show toggle result
Private Sub ShowToggleResult()
If MenuStartUp.Checked Then
VBMAN.Toast.Show "Added to auto-start"
Else
VBMAN.Toast.Show "Cancelled auto-start"
End If
End SubWith Startup Parameters
vb
' Toggle auto-start and pass startup parameters
Private Sub MenuStartUp_Click()
' Parameter: minimize to tray after startup
If VBMAN.StartUp.Toggle("my-app", App, "--minimized", "--autostart") Then
Debug.Print "Auto-start setting successful"
End If
End SubAfter startup, parameters can be read via Command$:
vb
Private Sub Form_Load()
' Check if auto-started
If InStr(Command$, "--autostart") > 0 Then
' Minimize to tray
Me.WindowState = vbMinimized
Me.Hide
End If
End Sub