Thread: add something to startup registry

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    3

    add something to startup registry

    ok how would i add this little program to startup when i restart the computer..
    Code:
    #include <isostream>
    #int main()
    {
    std::cout<<"hello world"<<std::end;
    return 0;
    }
    you will i laugh i know , but i am just trying to figure out how to add it so the exe will add to registry current version and startup by its self 
    thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Put it in your startup group would be the easiest thing to do probably.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    no i need it so when its opened ...it puts the registry vaule in regedit
    Last edited by Anddos22; 08-21-2005 at 07:01 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So you want something which worms it's way into the users registry so it restarts itself each time the program runs?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    well not worms its way , just when you run this it adds a reg key to autostart when the computer starts....i am just experimenting

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Anddos22
    well not worms its way , just when you run this it adds a reg key to autostart when the computer starts....i am just experimenting
    What final goal do you have in mind?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Code:
    #include <windows.h>
    
    #define RUN_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"
    
    int addRunEntry(char *name, char *path);
    
    int main()
    {
        addRunEntry("bob", "c:\\niceprogram\\nonmaliciousprogram.exe");
    }
    
    int addRunEntry(char *name, char *path)
    {
        HANDLE key;
        int len = strlen(path) + 1;
        LONG r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, RUN_KEY, 0, KEY_SET_VALUE, &key);
        
        if (r != ERROR_SUCCESS) {
            // unable to open key for adding values.
            return 1;
        }
    
        r = RegSetValueEx(key, name, 0, REG_SZ, path, len);
        if (r != ERROR_SUCCESS) {
            RegCloseKey(key);
            // unable to change registry value.
            return 1;
        }
            
        RegCloseKey(key);
    
        // success
        return 0; 
    }
    Last edited by Brian; 08-21-2005 at 08:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding program to startup
    By VeX92 in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2007, 01:08 AM
  2. Dynamically add statis text to a dialog box
    By earth_angel in forum Windows Programming
    Replies: 8
    Last Post: 06-23-2005, 01:28 PM
  3. How to add a file to a project in bloodshed.
    By Smeep in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 09:29 PM
  4. Add and delete functions
    By Ana Val sazi in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2002, 09:59 PM
  5. Cannot add file .c to C++ project
    By ooosawaddee3 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2002, 11:04 PM