Click to See Complete Forum and Search --> : Load application at startup
Dorothy
Jul 31st, 2002, 10:54 PM
I need to Load application at startup of windows?
Edneeis
Jul 31st, 2002, 11:08 PM
Add the path and exe file to the Run Value of the Software/Microsoft/Windows/CurrentVersion key of the registry.
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.
~*McoreD*~
Jan 18th, 2004, 06:55 AM
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).
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
Pirate
Jan 18th, 2004, 07:04 AM
Put this at the very top of your class file .
Imports Microsoft.Win32
~*McoreD*~
Jan 18th, 2004, 07:18 AM
Thank you very much Pirate! :)
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:
Pirate
Jan 18th, 2004, 07:23 AM
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 .
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.