![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Mar 2006 Location: USA::Colorado
Posts: 148
| Get program to copy itself into program files, then start on startup. 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");
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 | |
| | #2 |
| CSharpener 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 | |
| | #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 | |
| | #4 |
| CSharpener 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 | |
| | #5 | |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,054
| Quote:
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 | |
| | #6 |
| Rampaging 35 Stone Welsh 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 | |
| | #7 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| This Code: const unsigned char* Code: BYTE*
__________________ 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:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |