View Full Version : Load on startup in VB

01-22-2005, 09:03 AM
I have been looking for a code which can load application on startup using Visual Basic and got plenty but failed to get a simple one as the codes which i got was bundled with other programs so couldn't understand the code and re-use it...

Can anyone send me the code to load application in Visual Basic on startup. thank you

01-23-2005, 06:53 AM
VB...what? .net? 6? 7?

using .net:

Imports Microsoft.Win32

Dim boolRegWrite As Boolean
Dim strPathToApp as String
Dim strAppName as String

strPathToApp = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"
strAppName = "My Application"
boolRegWrite = WriteToRegistry(RegistryHive.LocalMachine, strPathToApp, strAppName, "Y")

Pubilc Function WriteToRegistry(ByVal ParentKeyHive As RegistryHive, ByVal SubKeyName As String, ByVal ValueName As String, _
ByVal Value As Object) As Boolean

Dim objSubKey As RegistryKey
Dim sException As String
Dim objParentKey As RegistryKey
Dim boolReturn As Boolean

boolReturn = True

Select Case ParentKeyHive
Case RegistryHive.ClassesRoot
objParentKey = Registry.ClassesRoot
Case RegistryHive.CurrentConfig
objParentKey = Registry.CurrentConfig
Case RegistryHive.CurrentUser
objParentKey = Registry.CurrentUser
Case RegistryHive.DynData
objParentKey = Registry.DynData
Case RegistryHive.LocalMachine
objParentKey = Registry.LocalMachine
Case RegistryHive.PerformanceData
objParentKey = Registry.PerformanceData
Case RegistryHive.Users
objParentKey = Registry.Users
End Select

'Open Registry Key
objSubKey = objParentKey.OpenSubKey(SubKeyName, True)

'create if doesn't exist
If objSubKey Is Nothing Then
objSubKey = objParentKey.CreateSubKey(SubKeyName)
End If

objSubKey.SetValue(ValueName, Value)

Catch ex As Exception
boolReturn = False

End Try

Return boolReturn

End Function

Note that I borrowed some code found here (http://www.freevbcode.com/ShowCode.asp?ID=174), cleaned it up, and added the appropriate registry key.


01-30-2005, 09:06 AM
i uses VB6. thank you though i got from microsoft.com on how to do it.

01-31-2005, 09:29 AM
A simple way i use is to put a shortcut in the startup folder when the application is installing.

02-01-2005, 10:17 AM
boss, anyone can delete that link anytime with ease. even by mistake! anyway i got what i'm looking for.thanx