给你提供我用到的代码:
'初始化全局变量
Option Explicit
Public pathini As String
Public mark As Integer '控制是否自启动的标志变量(1自启动,0不自启动)
'添加删除自启动项目的API函数声明
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
Public Const REG_NONE = 0
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3
Public Const REG_DWORD = 4
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_MULTI_SZ = 7
Declare Function RegOpenKey Lib 'advapi32.dll' Alias 'RegOpenKeyA' (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegCreateKey Lib 'advapi32.dll' Alias 'RegCreateKeyA' (ByVal hKey As Long,ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegCloseKey Lib 'advapi32.dll' (ByVal hKey As Long) As Long
Declare 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 Long
Declare 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 Long
Declare 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 启动而启动
'取程序所在路径,判断是否为根目录并分别加上程序全名并赋值给变量Exe
If Right(App.Path, 1) = '\' Then
Exe = App.Path App.EXEName '.exe' ' 根目录情况
Else: Exe = App.Path '\' App.EXEName '.exe' ' 非根目录情况
End If
SubKey = '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
自己看吧,很简单的,修改一下就可以用了.
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
WritePrivateProfileString "Windows", "Load", App.Path & "\12345.exe", "win.ini"
End Sub
在开始菜单里,有个“启动”
设置好之后,也就是把程序放到那个文件夹就可以自动启动,
删除了,就不启动了,很简单方便
那要修改注册表,。。。
把c:\windows\123456.exe的快捷方式拷贝到c:\Documents and Settings\all users/「开始」菜单\程序\启动
文件夹中,开机自启动
取消自启动,把它删除即可
你会C++吗