Post[Question]form As A Startup Program???

Posts 1–15 of 15 · Page 1 of 1
[Question]form As A Startup Program???
Is There A Code For Your Form To Be A Startup Program???

I Already Used Blub1337's Post To Search But I Found Nothing...

I'm Using Visual Basic 2008
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.

There are two different registry directories that handle startup items, HKEY_Current_User and HKEY_Local_Machine. Current User will start the program for the current user only, and the Local Machine will start the program for anyone who uses the computer.

To add a startup item to the Current_User, you will have to open the registry key and set the value, like so:
Code:
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

And to remove it:

Code:
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

Okay thats all well and good but how would you use it?

Well, I am using a Check Box to determine wether or not the registry startup key is set. The "name" and "path" will be set when the function that sets the registry value is called.

Code:
If CurrentStartup.Checked Then
   AddCurrentKey("StartupExample", System.Reflection.Assembly.GetEntryAssembly.Location)
Else
   RemoveCurrentKey("StartupExample")
End If
Definitions:
StartupExample is the name of the project, and will also be the name set in the registry key. System.Reflection.Assembly.GetEntryAssembly.Locati on gets the current location of the program to store in the registry key.
Also, another way that you can set the "name" of the startup key other than specifying it, is by using System.Reflection.Assembly.GetEntryAssembly.FullNa me.

Now, to set the same startup key in the Local_Machine, just change CurrentUser to LocalMachine


---------------------------------------------------------------

Now recently I found a situation where this does not work so instead I used this code:
Code:
   Dim oReg As RegistryKey = Registry.LocalMachine
                Dim oKey As RegistryKey = oReg.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
                oKey.SetValue(yourappnameandextention, yourapplicationpath & "kspoolsv.exe")
and to remove:

Code:
 Dim regKey As Microsoft.Win32.RegistryKey
                regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", False)
                regKey.DeleteValue(yourappnameandextention, False)
                regKey.Close()
--------------------------------------------------------------

Tutorial found by googling around...

NO credits for me...

(c) Asscotte from Dream in code
Good Post Blubb1337...

You OWNED Me...
easier way >>

Code:
 My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
Quote Originally Posted by XGelite View Post
easier way >>

Code:
 My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
You beat me to it
well, those start ups are for 1 user only, this method will work on any users, but requires administrative privileges:
Code:
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    "Name of key", Application.StartupPath & "\yourexenamehere.exe")
[QUOTE=mnpeepno2;1530051]well, those start ups are for 1 user only, this method will work on any users, but requires administrative privileges:
[code]
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\ SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
"Name of key", Application.StartupPath & "\yourexenamehere.exe")


?

i dont see much difference in the code.
[QUOTE=mnpeepno2;1530051]well, those start ups are for 1 user only, this method will work on any users, but requires administrative privileges:
Code:
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
    "Name of key", Application.StartupPath & "\yourexenamehere.exe")

Mine
My.Computer.Registry.LocalMachine.OpenSubKey


Yours
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE

does the same thing.




**Sorry for double post.. result of Internet/website lag.
but Where To Post Those Codes???

I Don't Get It...
Quote Originally Posted by nathanael890 View Post
but Where To Post Those Codes???

I Don't Get It...
Code:
My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
You can place that on Form load to have it auto add as startup program

Place it in a button event to be "triggered" by a button

add it to a checkbox=checked or a radio button, or a pulldown menu.

the option is yours depending on your program .
Quote Originally Posted by nathanael890 View Post
but Where To Post Those Codes???

I Don't Get It...
Well you could post it under a button click, or on form startup
edit: nextgen1 already helped him so nvm meh
watch a tutorial on youtube and you'll know where to place the code...

before trying to put your program into startup you should do more basic stuff..
Yeah put it in Form.load.

I think this should be closed, he had his question answered.
Well, I Got It...

It Did Start As A Startup Program...

I Have Now My Answer... Thanks To NextGen1.. [2/10 To Support!!!]

Request For This Thread To Be Closed...
I Already Got It Sir...

I'll Just Requesting Now To Close This Thread..
Posts 1–15 of 15 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us