C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-29-2008, 03:30 PM   #1
Registered User
 
Join Date: Mar 2006
Location: USA::Colorado
Posts: 148
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~
guitarist809 is offline   Reply With Quote
Old 02-29-2008, 03:32 PM   #2
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,242
just make a shortcut and place it into
Start/Programs/StartUp folder
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 02-29-2008, 03:38 PM   #3
Registered User
 
Join Date: Mar 2006
Location: USA::Colorado
Posts: 148
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~
guitarist809 is offline   Reply With Quote
Old 02-29-2008, 03:48 PM   #4
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,242
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.
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 02-29-2008, 06:17 PM   #5
Registered User
 
Join Date: Mar 2005
Location: Mountaintop, Pa
Posts: 1,054
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;
}
BobS0327 is offline   Reply With Quote
Old 03-03-2008, 09:39 AM   #6
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
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
__________________
He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet
abachler is offline   Reply With Quote
Old 03-03-2008, 09:42 AM   #7
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program Plan Programmer_P C++ Programming 0 05-11-2009 01:42 AM
Help to copy files in c++ Helgso C++ Programming 52 11-21-2008 08:50 AM
Data Question about Reading Files: Encapsulated Inventory Program in C++ goron350 C++ Programming 26 06-15-2005 02:38 PM
fopen(); GanglyLamb C Programming 8 11-03-2002 12:39 PM
copy two files into one waldis C++ Programming 4 10-20-2002 06:08 PM


All times are GMT -6. The time now is 07:24 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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