' 定义API
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _ (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private 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
Private Sub command1_Click() Dim hKey As Long, SubKey As String, strExe As String, Ret As Long
hKey = &H80000001 SubKey = "software\microsoft\windows\currentversion\run"
' 设定运行的程序 C:\C:\Windows\Notepad.exe strExe = "C:\Windows\Notepad.exe" RegCreateKey hKey, SubKey, Ret RegSetvalueEx Ret, "记事本", 0, 1, ByVal strExe, LenB(strExe) RegCloseKey Ret MsgBox strExe & " 程序已经被设定成 windows 启动时自动被执行的程序!" End Sub
|