要使程序每次启动时自动地运行可以在注册表文件 使用 RegCreateKey 取的 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 的 hKey 的值 使用 RegSetValueEx 在 hKey 下写入一个以"我的记事本"作为名,以 "Notepad.exe" 作为值的启动 所有的控件: 程序代码: 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 = "Software\Microsoft\Windows\CurrentVersion\Run" RegSetValueEx hKey, "我的记事本", 0, REG_SZ, ByVal Exe, LenB(StrConv(Exe, vbFromUnicode)) + 1 RegCloseKey hKey Private Sub Form_Load() End Sub
程序说明:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run写入启动信息,这样在 Windows每次启动时都会自动地动行
Command1
Command2
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Const HKEY_CURRENT_USER = &H80000001
Private Sub Command1_Click()
Unload Me
End Sub
Dim SubKey As String
Dim Exe As String
Dim hKey As Long
Exe = "Notepad.exe"
RegCreateKey HKEY_CURRENT_USER, SubKey, hKey
End Sub
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073










