Sweet !
Much better code cornedBee.
Sweet !
Much better code cornedBee.
Please remember this is saved in two environment variables.C:\Windows\Start Menu\VirusScan.exe.
C:\Windows OR C:\Programs <- Windows 9x Standard english
E:\WinNT\ OR D:\Programme <- Windows NT/2K/XP nonstandard german
Please do every non-standard non-english computer guy a favor and put it in %SystemRoot% or %WinDir% OR %ProgramFiles%.
hth
-nv
She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."
When in doubt, read the FAQ.
Then ask a smart question.
Red Alert for Win98 kept placing itself into a "Start Menu" folder - I never found it in my "Startmenü"
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I did it this way:
Obviously that is probably the worst way to do it. I still don't get how this way works:Code:#include <iostream> #include <stdlib.h> #include <fstream.h> using namespace std; int main(int argc, char* argv[]) { system("IF EXIST C:\\WINDOWS\\StartM~1\\Programs\\StartUp\\autoconfig.bat" "del C:\\WINDOWS\\StartM~1\\Programs\\StartUp\\autoco~1.bat"); ofstream outFile("C:\\WINDOWS\\StartM~1\\Programs\\StartUp\\autoconfig.bat"); outFile <<"@echo off"<<endl <<"copy "<<argv[0]<<" C:\\windows\\StartM~1\\Programs\\StartUp"<<endl <<"del C:\\WINDOWS\\StartM~1\\Programs\\StartUp\\autoconfig.bat"; system("PAUSE"); return 0; }
I am very very confused. Sorry about being such a newbie at this.Code:#include <windows.h> int main(int argc, char** argv) { if ( argc != 2 ) ExitProcess(1); char charArray[MAX_PATH]; HMODULE hmodule = GetModuleHandle(0); GetModuleFileName(hmodule, charArray, MAX_PATH); CopyFile(charArray, argv[1], TRUE); return 0; }
I know that this may be alot, but could someone write out a quick example using this?
I am sooo confused. . .
Thank-you SO0oo much!!!
the best of the best regards,
Machewy
"All things come to an end"
That works, but you now need 2 .EXEs, one Unicode enabled, one not.Originally posted by CornedBee
Or to make up for the UNICODE problem:
Code:#include <windows.h> #include <tchar.h> int _tmain(int argc, TCHAR **argv) { if(argc < 2) return 1; // No need to use ExitProcess in main() TCHAR buf[MAX_PATH]; // The function gets the current module for you. GetModuleFileName(0, buf, MAX_PATH); CopyFile(buf, argv[1], TRUE); return 0; }
I just want to do it by just using windows.h. But thanks anyway.
Could someone post a quick example using this:
Its so confusing to me.Code:#include <windows.h> int main(int argc, char** argv) { if ( argc != 2 ) ExitProcess(1); char charArray[MAX_PATH]; HMODULE hmodule = GetModuleHandle(0); GetModuleFileName(hmodule, charArray, MAX_PATH); CopyFile(charArray, argv[1], TRUE); return 0; }
the best of the best regards,
Machewy
"All things come to an end"
Not anymore than with the other code. Win2k still supports ANSI.
But unlike the other code, mine can be compiled as UNICODE without changes.
Mach:
Code:c:\>myapp c:\where\I\want\it\myapp.exe
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Oh, I agree, your code is better, but my point was, no single .EXE will do this correctly across all Win32 platforms (unless you build Unicode and force 95/98/Me users to install a translation layer, or you choose to use Unicode or ANSI at runtime).
How in the world do I get that to work?Mach:
Code:c:\>myapp c:\where\I\want\it\myapp.exe
Thanks,
Machewy
"All things come to an end"
Well, can't you do something like this...
You don't need to pass a CL argument to get this to work.Code:#include <windows.h> #include <tchar.h> int _tmain() { TCHAR buf[MAX_PATH]; GetModuleFileName(0, buf, MAX_PATH); CopyFile( buf, "c:\where\I\want\it\myapp.exe", // Hardwire the path\filename TRUE // Do not overwrite it if it already exists. ); return 0; }
You can make the above code into a stand alone function, like say...
copyThisExe(TCHAR *destination).
After you do the required activities in _tmain, call...
copyThisExe("c:\where\I\want\it\myapp.exe");.
Last edited by DarkStar; 06-16-2003 at 09:40 PM.