10 Replies - 21344 Views - Last Post: 29 October 2008 - 05:57 PM Rate Topic: -----

#1 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Start program when windows starts

Posted 20 November 2006 - 07:57 AM

How can I get my application to start with windows? I know I can add a link to the "startup" folder and it will sometimes start when windows starts, but that doesn't work all the time.

is there a code or an option or something I can use?
Is This A Good Question/Topic? 0
  • +

Replies To: Start program when windows starts

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Start program when windows starts

Posted 20 November 2006 - 12:04 PM

You could also add an entry into the Run key in the registry. This and adding to the startup folder are the only two ways I know of having an application execute on startup of Windows.

You will need to add it as a new String.

The key is located here:
My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run


Was This Post Helpful? 0
  • +
  • -

#3 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Start program when windows starts

Posted 20 November 2006 - 12:22 PM

ok, how do i access the registry in code though?

I got My.Computer.Registry.LocalMachine... and that's where I peter out
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Start program when windows starts

Posted 20 November 2006 - 01:45 PM

First thing you need to do is import Imports Microsoft.Win32. Also make sure you have administrative privileges on the computer, otherwise none of this will work.

Then to give you an example of how to code it:
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
regKey.SetValue("MyExecutable", "C:\MyExecutable.exe")
regKey.Close()



First step is to create a RegistryKey data type to contain the key of where you want to write the information. Make sure the boolean is set to True, this means you want to read/write to the SubKey. If it is false then it will be read only.

The next step is to set the value of the new entry using the SetValue method. The first parameter is the name it will be called inside the registry, can be pretty much anything you want to call it.

The second parameter is the physical path to where you have your executable stored.

Last but not least, DON'T forget to close the SubKey when you are done.

This example will create a value name in the Run SubKey called MyExecutable and the value data of C:\MyExecutable.exe.
Was This Post Helpful? 1

#5 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Start program when windows starts

Posted 20 November 2006 - 01:56 PM

I actually figured it out before this. But it's good because now other people can read this.

Question though. What happens if I forget to close the subkey?
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Start program when windows starts

Posted 20 November 2006 - 02:24 PM

Per the MSDN

Quote

Closes the key and flushes it to disk if its contents have been modified.


My understanding is that it basically writes the registry changes to disk, otherwise the changes only exist in the registry that is currently loaded into memory and as such are lost upon reboot.

RegistryKey.Close method MSDN.
Was This Post Helpful? 0
  • +
  • -

#7 the_hangman  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Start program when windows starts

Posted 20 November 2006 - 02:30 PM

You are wise
Was This Post Helpful? 0
  • +
  • -

#8 st0ne2thedge  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 23-July 08

Re: Start program when windows starts

Posted 28 October 2008 - 02:09 AM

Hi, i did exactly the same thing in Windows Vista and the ex.message noted that i do not have the permission to do this....
Any chance you know a solution to this problem?:s
Was This Post Helpful? 0
  • +
  • -

#9 Damage  Icon User is offline

  • Lord of Schwing
  • member icon

Reputation: 41
  • View blog
  • Posts: 1,108
  • Joined: 05-June 08

Re: Start program when windows starts

Posted 28 October 2008 - 03:14 AM

i don't know the benefits of one over the other but i found the easiest thing to do is to place a shortcut in the startup folder.
Was This Post Helpful? 0
  • +
  • -

#10 st0ne2thedge  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 23-July 08

Re: Start program when windows starts

Posted 29 October 2008 - 03:17 PM

Thx
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Start program when windows starts

Posted 29 October 2008 - 05:57 PM

What about creating a shortcut in the startup directory?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1