每次启动 Windows 时自动运行程序

2008-04-09 04:42:37来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

程序说明:

  要使程序每次启动时自动地运行可以在注册表文件

  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run写入启动信息,这样在 Windows每次启动时都会自动地动行

  使用 RegCreateKey 取的 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run 的 hKey 的值

  使用 RegSetValueEx 在 hKey 下写入一个以"我的记事本"作为名,以 "Notepad.exe" 作为值的启动

所有的控件:

Command1
Command2

程序代码:

Modul31
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 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 HKEY_CURRENT_USER = &H80000001

Public Const REG_SZ = 1

Form1
Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Command2_Click()
Dim SubKey As String
Dim Exe As String
Dim hKey As Long

SubKey = "Software\Microsoft\Windows\CurrentVersion\Run"
Exe = "Notepad.exe"
RegCreateKey HKEY_CURRENT_USER, SubKey, hKey

RegSetValueEx hKey, "我的记事本", 0, REG_SZ, ByVal Exe, LenB(StrConv(Exe, vbFromUnicode)) 1

RegCloseKey hKey


End Sub

Private Sub Form_Load()

End Sub

156

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:妙用GetSystemMetrics函数

下一篇:列举系统中所有窗口