How to add startup program to windows?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • the Snake
    New Member
    • Jan 2011
    • 1

    How to add startup program to windows?

    Hi i googled this topic for a while now the closest ive been to finding the answer was a comment that said:
    "Create new string value in [HKEY_CURRENT_US ER\Software\Mic rosoft\Windows\ Curre ntVersion\Run]

    like "Notepad"="c:\w indows\notepad. exe"."

    i'm new to programming, what does the value in the "[]" mean and how would i add a string to it
  • Samuel Jones
    New Member
    • Jan 2011
    • 48

    #2
    What does your program do?
    How reliant is your program on starting up with windows?

    The reason i ask is because that not many people like having 'junk' programs starting up with their computers.

    Avoid adding startup commands to the registry unless required.

    If you are making an update feature, look at alternatives such as checking when the program starts and give the user the option to add it to the registry.

    If you make a simple add-on utility, such as a program that allows shortcut-key-combinations to programs, make it simple and place it in the 'C:\Documents and Settings\All Users\Start Menu\Programs\S tartup\' folder.

    Bad things happen in the registry, that can 'brick' a computer, avoid it if you can.

    On another note, I'm working on a solution to your question.

    Comment

    • Samuel Jones
      New Member
      • Jan 2011
      • 48

      #3
      Found a solution:

      this is the code:
      Code:
      using Microsoft.Win32; //Don't forget this line
      
      namespace WindowsFormApplication1
      {
      public partial class Form1 : Form
          {
              string myProgName = "My Program Name";
              string myProgPath = @"My Program Path";
      
              //If your program has commandline arguments uncomment these lines:
              //string myProgCommands = "CommandlineArguments";
              //myProgPath = "\"" + myProgPath + "\" " + myProgCommands;
              
              private void WriteStartupKey()
              {
                  RegistryKey rkeyRoot = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
      
                  rkeyRoot.SetValue(myProgName, myProgPath, RegistryValueKind.String);
                  MessageBox.Show("Value Created");
                  rkeyRoot.Close();
              }
          }
      }
      To delete this key use this code:
      Code:
      RegistryKey rkeyRoot = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
      rkeyRoot.DeleteValue(myProgName);
      rkeyRoot.Close();

      Comment

      • Subin Ninan
        New Member
        • Sep 2010
        • 91

        #4
        I agree with Samuel, you can add startup entries using startup folder easily.

        Create registry entry under CURRENTUSER key to avoid permission issues.

        Code:
         Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run").SetValue("Notepad", "c:\windows\notepad.exe", RegistryValueKind.String);

        Comment

        Working...