要使程序每次啟動時自動地運行可以在注冊表文件
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun寫入啟動信息,這樣在 Windows每次啟動時都會自動地動行
使用 RegCreateKey 取的 HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun 的 hKey 的值
使用 RegSetValueEx 在 hKey 下寫入一個以"我的記事本"作為名,以 "Notepad.exe" 作為值的啟動
所有的控件:
| Command1 Command2 |
程序代碼:
Modul31 Public 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Const REG_SZ = 1 Form1 Private Sub Command2_Click() SubKey = "SoftwareMicrosoftWindowsCurrentVersionRun" RegSetValueEx hKey, "我的記事本", 0, REG_SZ, ByVal Exe, LenB(StrConv(Exe, vbFromUnicode)) + 1 RegCloseKey hKey
Private Sub Form_Load() End Sub |