Hai I am Rajeesh.
New to Vb.net. I am developing a simple program. I want to run my application automatically when windows start. Please tell me how can I do this adding Windows Registry key.....

Thanks
Rajeesh

You mean that you want to start up your application from the registry?

Install application to run from the registry:

''' <summary>
''' Installs an application to start from the registry when Windows starts
''' </summary>
''' <param name="AppName">Application's name</param>
''' <param name="AppPath">Full path to the application</param>
''' <param name="InstallToLocalMachine">Install to LM, otherwise install to current user</param>
''' <returns>True if successfully installed</returns>
''' <remarks>Compatible with Windows XP and Vista</remarks>
Public Function StartUpInstall(ByVal AppName As String, ByVal AppPath As String, _
  ByVal InstallToLocalMachine As Boolean) As Boolean
  '
  ' Install to registry
  ' If LM then uses HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  ' Otherwise uses HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  '
  Dim RegRoot As RegistryKey
  Dim RegKey As RegistryKey

  Try
    If InstallToLocalMachine Then
      RegRoot = Microsoft.Win32.Registry.LocalMachine
      RegKey = RegRoot.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
        RegistryKeyPermissionCheck.ReadWriteSubTree, _
        Security.AccessControl.RegistryRights.SetValue)
      RegKey.SetValue(AppName, AppPath, RegistryValueKind.String)
      Return True
    Else
      RegRoot = Microsoft.Win32.Registry.CurrentUser
      RegKey = RegRoot.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
        RegistryKeyPermissionCheck.ReadWriteSubTree, _
        Security.AccessControl.RegistryRights.SetValue)
      RegKey.SetValue(AppName, AppPath, RegistryValueKind.String)
      Return True
    End If
  Catch ex As Exception
    Return False
  End Try

End Function

Remove application from the registry:

''' <summary>
''' Uninstalls an application not to start from the registry when Windows starts
''' </summary>
''' <param name="AppName">Application's name</param>
''' <param name="InstallToLocalMachine">Uninstall from LM, otherwise uninstall from current user</param>
''' <returns>True if successfully uninstalled</returns>
''' <remarks>Compatible with Windows XP and Vista</remarks>
Public Function StartUpUnInstall(ByVal AppName As String, _
  ByVal InstallToLocalMachine As Boolean) As Boolean
  '
  ' UnInstall from registry
  ' If LM then uses HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  ' Otherwise uses HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  '
  Dim RegRoot As RegistryKey
  Dim RegKey As RegistryKey

  Try
    If InstallToLocalMachine Then
      RegRoot = Microsoft.Win32.Registry.LocalMachine
      RegKey = RegRoot.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
        RegistryKeyPermissionCheck.ReadWriteSubTree, _
        Security.AccessControl.RegistryRights.SetValue)
      RegKey.DeleteValue(AppName, False)
      Return True
    Else
      RegRoot = Microsoft.Win32.Registry.CurrentUser
      RegKey = RegRoot.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
        RegistryKeyPermissionCheck.ReadWriteSubTree, _
        Security.AccessControl.RegistryRights.SetValue)
      RegKey.DeleteValue(AppName, False)
      Return True
    End If
  Catch ex As Exception
    Return False
  End Try

End Function

I think I've originally grabbed these snippets from somewhere. So the credits go to someone who's name I don't remember anymore :-/

This article has been dead for over six months. Start a new discussion instead.