Question Run Project on Startup

DerpBane

New member
Joined
Nov 26, 2013
Messages
4
Programming Experience
Beginner
Hello, I'm very new to the whole coding/programming scene...

I've made a project in VB.net 2008. I want the form that it uses to be displayed when my computer starts up - it is basically just a little message, a reminder to do something.

I know there are some recent posts that I have seen describing how to do this, but the coding that they use don't work for me, my vb.net says that they contain errors. I think it might be because I'm running good old 2008.

So here's my question: how do I get my computer to run my vb.net 2008 program on start-up, what could go wrong if I mess the code up somehow, and can you explain some of the reasoning behind the code (it helps me to understand in more depth, every little helps me to improve, although I have already Googled a lot of keywords from previously seen programs and have some understanding)?

thanks? :)
 
If the code you have didn't work for you then most likely you used it incorrectly. Even if you didn't, the principles will still most likely be sound and you just need a few simple adjustments. Show us what you did and tell us what happened and then we can help you fix the issues.
 
Public Class Form1
Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey _
("Software\Microsoft\Windows\CurrentVersion\Run", True)
key.SetValue(name, path)
End Sub


Private Sub RemoveCurrentKey(ByVal name As String)
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey _
("Software\Microsoft\Windows\CurrentVersion\Run", True)
key.DeleteValue(name, False)
End Sub


If CurrentStartup.Checked Then
AddCurrentKey("StartupExample", System.Reflection.Assembly.GetEntryAssembly.Location)
Else
RemoveCurrentKey("StartupExample")
End If




End Class

"Dim Key As RegistryKey" -- Apparently 'type RegistryKey is not defined'
And the entire If statement is broken because it is outside of a 'method body' AND 'Remove/AddCurrentKey' needs a declaration.

GoodLuck -> Followed this guide: Running Your Program On Windows Startup Either The Current User Or The - VB.NET Tutorials | Dream.In.Code
Thanks for the reply (y)
 
article said:
Now, since we are accessing the registry, you will need to import Microsoft.Win32, which contains the part of the .NET Framework that handles the registry.
That means add at top of code file:
Imports Microsoft.Win32

You can also let the IDE do that job for you by using its Error Correction Options dialog, you'll see RegistryKey has a squiggly blue line with a red square at the end, when you mouse hover the red square an exclamation icon shows and you can click it.
And the entire If statement is broken because it is outside of a 'method body'
Yes, you need to add code like that into one of your methods or event handler methods.
 
Apparently 'type RegistryKey is not defined'
I suggest that you follow the Blog link in my signature and check out my post on Assemblies & Namespaces.
And the entire If statement is broken because it is outside of a 'method body' AND 'Remove/AddCurrentKey' needs a declaration.
That's pretty elementary stuff. I would suggest that you work your way through a beginners tutorial to get a proper grasp of the basics first before trying anything fancy like working with the Registry. There's a link in my signature below.
 
Thanks! You're a trooper! I have a great deal of gratitude to pass onto you sire!

Thankyou! I get the impression you're a pretty well accomplished programmer, much respect!
 
Back
Top