-
Mar 12th, 2003, 04:17 PM
#1
VB - Add/Remove your program to computer startup (through the registry)
Add two command buttons (Command1 , Command2) and add the following code :
VB Code:
Option Explicit
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 RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) 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 RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData 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 Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_DWORD = 4 ' 32-bit number
Private Const ERROR_SUCCESS = 0&
Public Enum pvpHK
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
End Enum
Private Const pvpRunHKey = "Software\Microsoft\Windows\CurrentVersion\Run"
Private Sub savestring(ByVal Hkey As Long, strPath As String, strValue As String, strData As String)
Dim keyhand As Long
Dim r As Long
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
If r = 87 Then
DeleteValue Hkey, strPath, strValue
End If
r = RegCloseKey(keyhand)
End Sub
Private Function DeleteValue(ByVal Hkey As Long, ByVal strPath As String, ByVal strValue As String)
Dim keyhand As Long
Dim r As Long
r = RegOpenKey(Hkey, strPath, keyhand)
r = RegDeleteValue(keyhand, strValue)
r = RegCloseKey(keyhand)
End Function
Public Function RunAtStartup(sAppTitle As String, strsAppName As String)
savestring pvpHK.HKEY_CURRENT_USER, pvpRunHKey, sAppTitle, strsAppName
End Function
Public Function RemoveFromStartup(sAppTitle As String, strsAppName As String)
DeleteValue pvpHK.HKEY_CURRENT_USER, pvpRunHKey, sAppTitle
End Function
Private Sub Command1_Click()
RunAtStartup App.Title, App.Path & "\" & App.EXEName & ".EXE"
End Sub
Private Sub Command2_Click()
RemoveFromStartup App.Title, App.Path & "\" & App.EXEName & ".EXE"
End Sub
Private Sub Form_Load()
Command1.Caption = "Add To Startup"
Command2.Caption = "Remove from Startup"
End Sub
Last edited by manavo11; Mar 12th, 2003 at 04:32 PM.
Has someone helped you? Then you can Rate their helpful post.
-
Dec 28th, 2005, 08:07 PM
#2
PowerPoster
Re: VB - Add/Remove your program to computer startup (through the registry)
run-time error '28':
out of stack space
-
Dec 29th, 2005, 08:30 AM
#3
Re: VB - Add/Remove your program to computer startup (through the registry)
Originally Posted by BrailleSchool
run-time error '28':
out of stack space
That generally means some kind of runaway recursion is going on.
What did you run/click on that resulted in the error, the RunAtStartup or RemoveFromStartup?
-
Dec 29th, 2005, 11:54 AM
#4
PowerPoster
Re: VB - Add/Remove your program to computer startup (through the registry)
Originally Posted by Hack
That generally means some kind of runaway recursion is going on.
What did you run/click on that resulted in the error, the RunAtStartup or RemoveFromStartup?
i put the code in my code window and ran it in the IDE and thats what i got.
-
Nov 14th, 2011, 06:46 AM
#5
New Member
Re: VB - Add/Remove your program to computer startup (through the registry)
I want the program should auto hide from startup
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|