I need to Load application at startup of windows?
Printable View
I need to Load application at startup of windows?
Add the path and exe file to the Run Value of the Software/Microsoft/Windows/CurrentVersion key of the registry.
VB Code:
Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) regKey.SetValue(Application.ProductName, Application.ExecutablePath)
I used the CurrentUser here but you can also use LocalMachine if you want it to load regardless of who the user is.
At last in the 4th page of my Search Results, I found the thread which I was looking for. :)
Can you guys please show me a sample code on how to use the above code?
I tried this: (you will see what I am trying to do: I am trying make it as feature that the user can turn on and off).
VB Code:
Private Sub mnuToolsStartup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuToolsStartup.Click mnuToolsStartup.Checked = Not mnuToolsStartup.Checked If mnuToolsStartup.Checked = True Then Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) regKey.SetValue(Application.ProductName, Application.ExecutablePath) Else Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) regKey.SetValue("") End If End Sub
But it keeps saying Type 'RegistryKey' is not defined.
Appreciate your help,
Learning something new everyday!
McoreD
Put this at the very top of your class file .
VB Code:
Imports Microsoft.Win32
Thank you very much Pirate! :)
VB Code:
Private Sub mnuToolsStartup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuToolsStartup.Click mnuToolsStartup.Checked = Not mnuToolsStartup.Checked If mnuToolsStartup.Checked = True Then Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) regKey.SetValue(Application.ProductName, Application.ExecutablePath) Else Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True) regKey.DeleteValue(Application.ProductName, False) End If End Sub
With that Imports Microsoft.Win32 I was able uncover DeleteValue.
And the above code just the job exactly how I want.
Thanks again,
McoreD
P.S: How we are supposed to know codes like Imports Microsoft.Win32 ? :bigyello:
You're welcome .;) .
By browsing Namespaces 'Hit Ctrl + Alt + J' in the Object Browser .
Imports keyword isn't nothing than a way to shortcut some lengthy path to namespaces and classes .