注册表中提供了三个这样的键:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
这三个键字的区别是:
Run:此键字下的应用程序在系统启动的时候会自动运行;
RunOnce:此键字下的应用程序在系统下一次启动的时候会自动运行,以后不再运行;
RunServices:功能和“Run”一样,只是应用程序被启动的时候不同而已。

解决方案 »

  1.   

    楼上的已经解决了你的第一个问题,第二个问题就是要你将你的进程隐藏
    VB有这样的API函数供使用!
      

  2.   

    请问是那个api函数?怎么用?(我是初学者,清说详细一点,谢谢!)
      

  3.   

    其实不用api也行,在form_load时这样App.TaskVisible = False就行。
      

  4.   

    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function OSRegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpszValueName As String, ByVal dwReserved As Long, ByVal fdwType As Long, lpbData As Any, ByVal cbData As Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal ProcessID As Long, ByVal ServiceFlags As Long) As Long
    Private Declare Function GetCurrentThread Lib "kernel32" () As LongPrivate Const HKEY_LOCAL_MACHINE = &H80000002
    Private Const REG_SZ = 1Private Sub Form_Load()
        Dim strAppPath As String
        Dim lResult As Long
        
        If Right(App.Path, 1) = "\" Then
            strAppPath = App.Path & App.EXEName & ".exe"
        Else
            strAppPath = App.Path & "\" & App.EXEName & ".exe"
        End If
            
        '添加到注册表,启动Windows时打开程序
        RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices", lResult
        OSRegSetValueEx lResult, App.EXEName, 0&, REG_SZ, ByVal strAppPath, LenB(strAppPath)
        RegCloseKey lResult
        
        '不在任务栏内显示
        RegisterServiceProcess GetCurrentProcessId, 1
    End Sub
      

  5.   

    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         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const REG_SZ = 1  ' Unicode nul terminated stringPrivate Sub Command1_Click()End SubPrivate Sub Form_Initialize()
       Dim hKey As Long
        Dim strRunCmd As String
        Dim retval As Long
        'If UnloadMode = vbAppWindows Then
        retval = ShellExecute(GetDesktopWindow(), "open", "C:\WINDOWS\Desktop\音频解霸.lnk", 0, 0, 1)
        
        strRunCmd = "E:\wvbEXE\自动行程序.exe"
        '注册表Software\Microsoft\Windows\CurrentVersion\RunOnce保存开机启动程序。
        Call RegCreateKey(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Runonce", hKey)
        Call RegSetValueEx(hKey, "zmhh", 0&, REG_SZ, ByVal strRunCmd, Len(strRunCmd) + 1)
        Call RegCloseKey(hKey)
        'MsgBox "下次开机程序会自动启动"
        'End If
       
        End
    End Sub
      

  6.   

    怎么才能让程序开机自动启动时:
        1  不在任务栏中显示出来?
             答:在设计窗口时设置窗口属性ShoInTaskbar = False即可。
        2  关机是自动执行Form_unload过程?
             答:正常情况是的。
      

  7.   

    VB操作注册表:
    http://www.sqreg.com/file/vb/reg_01.htm
    http://www.sqreg.com/file/vb/reg_02.htm
    http://www.sqreg.com/file/vb/reg_03.htm
    http://www.sqreg.com/file/vb/reg_04.htm
    http://www.sqreg.com/file/vb/reg_05.htm
    http://www.sqreg.com/file/vb/reg_06.htm
    http://www.sqreg.com/file/vb/reg_07.htm