# Re: 小弟我做好了程式但是..........

Posted by 小琳 on July 08, 1999 at 22:14:15:

In Reply to: 小弟我做好了程式但是.......... posted by Likol on July 08, 1999 at 18:25:04:

: 我的程式写好了,但我希望当我一进入win98或95时
: 这个程式就会执行(就是在出现windows登入之前执
: 行,或是不管用什么名字登入,登入后执行),我该怎
: 么做ㄚ?????

:::可利用以下的程式就可以:
Option Explicit

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

Sub Main()
Dim hKey As Long, SubKey As String, Exe As String

SubKey = "Software\Microsoft\Windows\CurrentVersion\Run"
Exe = "Value值"
RegCreateKey HKEY_Local_Machine, SubKey, hKey
RegSetValueEx hKey, "程式名称", 0, REG_SZ, ByVal Exe, _
LenB(StrConv(Exe, vbFromUnicode)) + 1
RegCloseKey hKey
MsgBox "程式已经被设定成 Windows 启动时自动被执行的程式！"
End Sub

Follow Ups: