یکم بگردی پیدا می کنی خدا گوگل را برای اینکار آفرید .
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim strSource As String, strDest As String
Private Sub Form_Load()
If App.PrevInstance = True Then End
strSource = App.path & IIf(Len(App.path) > 0, "", Empty)
strSource = strSource & App.EXEName & ".exe"
strDest = WinDrive & "Documents and SettingsAll UsersStart MenuProgramsStartup"
FileCopy strSource, strDest & App.EXEName & ".exe"
End Sub
Private Function WinDrive() As String
Dim strDrive As String
strDrive = Space(500)
A = GetWindowsDirectory(strDrive, Len(strDrive))
strDrive = Left(strDrive, 3)
WinDrive = strDrive
End Function
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
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey 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 Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
Dim strAppPath As String
Private Sub Command1_Click()
AddToRun App.Title, strAppPath
End Sub
Private Sub Command2_Click()
RemoveFromRun App.Title
End Sub
Private Sub Form_Load()
Command1.Caption = "Add to Run"
Command2.Caption = "Remove from Run"
strAppPath = IIf(Len(App.path) > 3, App.path & "", App.path)
strAppPath = strAppPath & App.EXEName & ".exe"
End Sub
'---------------------------------------------
Private Sub AddToRun(ProgramName As String, FileToRun As String)
Call SaveString("SoftwareMicrosoftWindowsCurrentVersion Run", ProgramName, FileToRun)
End Sub
Private Sub RemoveFromRun(ProgramName As String)
Call DeleteValue("SoftwareMicrosoftWindowsCurrentVersio nRun", ProgramName)
End Sub
Private Sub SaveString(strPath As String, strValue As String, strdata As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(HKEY_LOCAL_MACHINE, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub
Private Function DeleteValue(ByVal strPath As String, ByVal strValue As String)
Dim keyhand As Long
Dim r As Long
r = RegOpenKey(HKEY_LOCAL_MACHINE, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function