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 comp
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.
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
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
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.
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
Simpley use this code:
Dim info As New FileInfo(application.startuppath)
info.CopyTo(My.Computer.FileSystem.SpecialDirectories.Programs + "\startup\myapp.exe")
hope it helps.