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

This is a discussion on Get program to copy itself into program files, then start on startup. within the Windows Programming forums, part of the Platform Specific Boards category; Hey everyone, I'm a beginner windows programmer, but I'm trying to make a program that copies itself into the windows ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    just make a shortcut and place it into
    Start/Programs/StartUp folder
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    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.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    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,189
    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
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    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, 07: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, 11:39 AM
  5. copy two files into one
    By waldis in forum C++ Programming
    Replies: 4
    Last Post: 10-20-2002, 06:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21