5

I'm programming a desktop application similar to Google desktop but with my own gadget with vb.net 2008 how can i make my application when the user install it on their computer to run at the time of start up?

Let assume that my application name is windowsAplication1 and I'm using windows XP and the program will be installed on C drive?

1
  • Just use simple way 1) Create a short Cut of your application on desktop 2) Copy it 3) Goto Start>> Programs>> Startup here "right click" using mouse and select open >> this will open the location of start menu.. 4) Paste that copied shortcut here.. 5) YOu are done with next restart this program will start automatically at startup :) Commented Jul 16, 2014 at 5:06

7 Answers 7

30

You can add it to registry with the following code

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath) 

you can remove it using

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName) 

The above code will add it to all users. You can add it to current user in the following key

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 

Or you can add a link to your application in the "Startup" folder.

I suggest you dont do it automatically it may irritate the user. I hate when apps add them automatically to Windows Startup. Give an option for the user to run the program on windows startup.

Sign up to request clarification or add additional context in comments.

4 Comments

Is it possible to start an executable on start windows and not on start the session of an user?
I got Exception User-Unhandled. System.Security.SecurityException: 'Requested registry access is not allowed.' How to fix this? I don't want to force user right click > run as administrator.
@ChristhoferNatalius I have same issue on windows 10 for all users, did you resolve it ?
@Web.11 I give up with registry, and just create shortcut in startup folder.
2

Simpley use this code:

Dim info As New FileInfo(application.startuppath) info.CopyTo(My.Computer.FileSystem.SpecialDirectories.Programs + "\startup\myapp.exe") 

hope it helps.

1 Comment

If your program has dependencies on files such as DLLs, you'll have to copy those as well to start-up path for the program to run correctly once it starts. But doing so might clutter your start-up path with all those files. So I would suggest it is better to first programmatically create a shortcut link file of the program and then copy this shortcut link file to the startup path.
2

A simple method

Imports Microsoft.Win32 ... Dim regKey As RegistryKey regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run",True) regKey.SetValue(Application.ProductName, Application.ExecutablePath) regKey.Close() 

Hope it helps

Comments

1

You Can Do this Using the code below

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' This is where you'll need to have the program ' set the check box to the previous selection that ' the user has set. It's up to you how you do this. ' For now, I'll set it as "unchecked". CheckBox1.Checked = False End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' The following code is a rendition of one provided by ' Firestarter_75, so he gets the credit here: Dim applicationName As String = Application.ProductName Dim applicationPath As String = Application.ExecutablePath If CheckBox1.Checked Then Dim regKey As Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) regKey.SetValue(applicationName, """" & applicationPath & """") regKey.Close() Else Dim regKey As Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) regKey.DeleteValue(applicationName, False) regKey.Close() End If ' Assuming that you'll run this as a setup form of some sort ' and call it using .ShowDialog, simply close this form to ' return to the main program Close() End Sub 

1 Comment

PLS Reply me soon :)
1
Imports Microsoft.Win32 ... Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", Application.ProductName, Application.ExecutablePath, RegistryValueKind.String) 

Comments

0

Just try this code :-

FileCopy("Name.Ext", Environment.GetFolderPath(Environment.SpecialFolder.Startup) & "\Name.Ext") 

Here (Name.Ext) :-

Name - Your Application's name. Ext - The Extension, it's of-course .exe

It's the simplest and best to use.

1 Comment

If your program has dependencies on files such as DLLs, you'll have to copy those as well to start-up path for the program to run correctly once it starts. But doing so might clutter your start-up path with all those files. So I would suggest it is better to first programmatically create a shortcut link file of the program and then copy this shortcut link file to the startup path.
0

Might be old topic but adding Imports System.Security.AccessControl.RegistryRights Should resolve System.Security.SecurityException: 'Requested registry access is not allowed.' trouble stated by Christhofer Natalius

Comments