回覆列表
  • 1 # kdilp25805

    給你提供我用到的程式碼:"初始化全域性變數Option ExplicitPublic pathini As StringPublic mark As Integer "控制是否自啟動的標誌變數(1自啟動,0不自啟動)"新增刪除自啟動專案的API函式宣告Public Const HKEY_CLASSES_ROOT = &H80000000Public Const HKEY_CURRENT_USER = &H80000001Public Const HKEY_LOCAL_MACHINE = &H80000002Public Const HKEY_USERS = &H80000003Public Const HKEY_PERFORMANCE_DATA = &H80000004Public Const HKEY_CURRENT_CONFIG = &H80000005Public Const HKEY_DYN_DATA = &H80000006Public Const REG_NONE = 0Public Const REG_SZ = 1Public Const REG_EXPAND_SZ = 2Public Const REG_BINARY = 3Public Const REG_DWORD = 4Public Const REG_DWORD_BIG_ENDIAN = 5Public Const REG_MULTI_SZ = 7Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As LongDeclare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long,ByVal lpSubKey As String, phkResult As Long) As LongDeclare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As LongDeclare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As LongDeclare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As LongDeclare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long"在登錄檔中新增刪除自啟動專案的模組Sub Main()" 定義hKey 為控制代碼變數、SubKey為登錄檔RUN專案變數、Exe為程式名變數Dim hKey As Long, SubKey As String, Exe As String"將程式設定成隨 Windows 啟動而啟動"取程式所在路徑,判斷是否為根目錄並分別加上程式全名並賦值給變數ExeIf Right(App.Path, 1) = "\" ThenExe = App.Path App.EXEName ".exe" " 根目錄情況Else: Exe = App.Path "\" App.EXEName ".exe" " 非根目錄情況End IfSubKey = "Software\Microsoft\Windows\CurrentVersion\Run" " 設定專案RegCreateKey HKEY_LOCAL_MACHINE, SubKey, hKey " 取得控制代碼RegSetValueEx hKey, "時間助手", 0, REG_SZ, ByVal Exe, LenB(StrConv(Exe, vbFromUnicode)) 1 " 寫入鍵值RegCloseKey hKey " 關閉控制代碼End Sub自己看吧,很簡單的,修改一下就可以用了.

  • 中秋節和大豐收的關聯?
  • 《神秘島主人公的英文名?神秘島》主人公?