|
-
Jul 31st, 2002, 10:54 PM
#1
[RESOLVED] Load application at startup
I need to Load application at startup of windows?
-
Jul 31st, 2002, 11:08 PM
#2
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.
-
Jan 18th, 2004, 07:55 AM
#3
Addicted Member
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
-
Jan 18th, 2004, 08:04 AM
#4
Sleep mode
Put this at the very top of your class file .
-
Jan 18th, 2004, 08:18 AM
#5
Addicted Member
Excellent!
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 ?
-
Jan 18th, 2004, 08:23 AM
#6
Sleep mode
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 .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|