Thread: Get program to copy itself into program files, then start on startup.

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    Get program to copy itself into program files, then start on startup.

    Hey everyone,

    I'm a beginner windows programmer, but I'm trying to make a program that copies itself into the windows "Program Files" folder and run on startup.

    This is a console program in c++ and I'm stuck.

    I tried doing something like:

    Code:
    system("mkdir %programfiles%\\AntiLeetSpeak");
    system("copy AntiLeetSpeak.exe %programfiles%\\AntiLeetSpeak\\AntiLeetSpeak.exe");
    It copied the executable into the program files folder, but now I have no clue how to make it startup on system start.

    I know you can place it in the registry (SOFTWARE\Microsoft\Windows\CurrentVersion\Run) - but as far as that goes, I'm stuck...
    ~guitarist809~

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    just make a shortcut and place it into
    Start/Programs/StartUp folder
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    I'd do that, it's just that people becides me are probably going to use this program and I would like it to be automatic...

    I used to have a code example of this (with functions like OpenRegEx() or something and you could set a value...)
    ~guitarist809~

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Do it automatic

    I prefer programs that do not play with the registry, and especiialy with the Run key, when it can be avoided.

    In your case - it definitely can be avoided.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Quote Originally Posted by guitarist809 View Post
    I'd do that, it's just that people becides me are probably going to use this program and I would like it to be automatic...

    I used to have a code example of this (with functions like OpenRegEx() or something and you could set a value...)
    Code:
    // Assuming that c:\program files\Myapp folder exists and the MyApp.exe is in this folder
    #pragma comment(lib, "advapi32.lib")
    
    #include <windows.h>
    #include <stdio.h>
    
    char szRunKey[] = {"Software\\Microsoft\\Windows\\CurrentVersion\\Run"};
    char szMyAppPath[] = {"C:\\Program Files\\MyApp\\MyApp.exe"};
    char szMyappSubKey[] = {"MyApp"};
    
    int main(void)
    {
        HKEY hKey;
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRunKey, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
        {
            if(RegSetValueEx(hKey, szMyappSubKey, 0, REG_SZ, (const unsigned char*)szMyAppPath, sizeof(szMyAppPath)) == ERROR_SUCCESS)
                printf("Create Run key successful\n");
            else printf("RegSetValueEx failed\n");
            RegCloseKey(hKey); 
        }
        else printf("RegOpenKeyEx key failed\n");
        return 0;
    }

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    and now that I have that little tidbit of information, we will do the same thing we do every night Pinky, TRY TO TAKE OVER THE WORLD, MUAHAHAHAHAHA

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This
    Code:
    const unsigned char*
    Can be shortened to
    Code:
    BYTE*
    And none of the API takes const IIRC, so it's just as much useless to cast into.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Help to copy files in c++
    By Helgso in forum C++ Programming
    Replies: 52
    Last Post: 11-21-2008, 08:50 AM
  3. Replies: 26
    Last Post: 06-15-2005, 02:38 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. copy two files into one
    By waldis in forum C++ Programming
    Replies: 4
    Last Post: 10-20-2002, 06:08 PM