My self install codes using startup folder - please comment
-
guys here are my self install codes for any applications it will copy itself to the startup folder and run it's not very efficient so i need u guys to advise on improvements works on win98,winxp codes that have been commented out are some of the stuff i previously tested and found to be unsuccessful :)
char *current_directory = new char[MAX_PATH]; // rem to delete this char *window_dir = new char[MAX_PATH]; // rem to delete this GetModuleFileName(theApp.m_hInstance, current_directory, MAX_PATH); SHGetSpecialFolderPath(NULL,window_dir, CSIDL_STARTUP,TRUE); strcat(window_dir,"\\sev.exe"); // FORCE IT TO BE IN STARTUP FOLDER // CopyFile(current_directory,window_dir,FALSE ) ; if( stricmp (current_directory , window_dir) != 0) // i am not in the correct dir { int set_file_result = SetFileAttributes(window_dir,FILE_ATTRIBUTE_NORMAL); if (set_file_result == 0)// if i cant set attrib, means wind_dir is empty, if i can set, means wind_dir not empty and i gotta del { CopyFile(current_directory,window_dir,FALSE ) ; ShellExecute(0,0,window_dir,0,0,0); delete[] window_dir; return 55; return 0; } BOOL delete_result = DeleteFile( window_dir); int bb = GetLastError(); if(delete_result == 0) // delete fails because of access denied { //BOOL seek_and_kill(char *window_dir ) , to kill the currently process so as to allow me to run { HANDLE hProcessSnap; PROCESSENTRY32 pe32; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if( hProcessSnap == INVALID_HANDLE_VALUE ) { return( FALSE ); } pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // and exit if unsuccessful if( !Process32First( hProcessSnap, &pe32 ) ) { CloseHandle( hProcessSnap ); // Must clean up the snapshot object! return( FALSE ); } BOOL next_result = 1; // TCHAR *szExeFile = {pe32.szExeFile}; while( ( stricmp( pe32.szExeFile , "sev.exe") != 0) && (next_result != FALSE ) ) { next_result = Process32Next(hProcessSnap, &pe32); } HANDLE kill_this_process = OpenProcess( PROCESS_ALL_ACCESS,0, pe32.th32ProcessID); TerminateProcess(kill_this_process , 999); // return 1; } while(!DeleteFile( window_dir) ) {}; } CopyFile(current_directory,window_dir,FALSE ) ; ShellExecute(0,0,window_d
-
guys here are my self install codes for any applications it will copy itself to the startup folder and run it's not very efficient so i need u guys to advise on improvements works on win98,winxp codes that have been commented out are some of the stuff i previously tested and found to be unsuccessful :)
char *current_directory = new char[MAX_PATH]; // rem to delete this char *window_dir = new char[MAX_PATH]; // rem to delete this GetModuleFileName(theApp.m_hInstance, current_directory, MAX_PATH); SHGetSpecialFolderPath(NULL,window_dir, CSIDL_STARTUP,TRUE); strcat(window_dir,"\\sev.exe"); // FORCE IT TO BE IN STARTUP FOLDER // CopyFile(current_directory,window_dir,FALSE ) ; if( stricmp (current_directory , window_dir) != 0) // i am not in the correct dir { int set_file_result = SetFileAttributes(window_dir,FILE_ATTRIBUTE_NORMAL); if (set_file_result == 0)// if i cant set attrib, means wind_dir is empty, if i can set, means wind_dir not empty and i gotta del { CopyFile(current_directory,window_dir,FALSE ) ; ShellExecute(0,0,window_dir,0,0,0); delete[] window_dir; return 55; return 0; } BOOL delete_result = DeleteFile( window_dir); int bb = GetLastError(); if(delete_result == 0) // delete fails because of access denied { //BOOL seek_and_kill(char *window_dir ) , to kill the currently process so as to allow me to run { HANDLE hProcessSnap; PROCESSENTRY32 pe32; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if( hProcessSnap == INVALID_HANDLE_VALUE ) { return( FALSE ); } pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // and exit if unsuccessful if( !Process32First( hProcessSnap, &pe32 ) ) { CloseHandle( hProcessSnap ); // Must clean up the snapshot object! return( FALSE ); } BOOL next_result = 1; // TCHAR *szExeFile = {pe32.szExeFile}; while( ( stricmp( pe32.szExeFile , "sev.exe") != 0) && (next_result != FALSE ) ) { next_result = Process32Next(hProcessSnap, &pe32); } HANDLE kill_this_process = OpenProcess( PROCESS_ALL_ACCESS,0, pe32.th32ProcessID); TerminateProcess(kill_this_process , 999); // return 1; } while(!DeleteFile( window_dir) ) {}; } CopyFile(current_directory,window_dir,FALSE ) ; ShellExecute(0,0,window_d
-
guys here are my self install codes for any applications it will copy itself to the startup folder and run it's not very efficient so i need u guys to advise on improvements works on win98,winxp codes that have been commented out are some of the stuff i previously tested and found to be unsuccessful :)
char *current_directory = new char[MAX_PATH]; // rem to delete this char *window_dir = new char[MAX_PATH]; // rem to delete this GetModuleFileName(theApp.m_hInstance, current_directory, MAX_PATH); SHGetSpecialFolderPath(NULL,window_dir, CSIDL_STARTUP,TRUE); strcat(window_dir,"\\sev.exe"); // FORCE IT TO BE IN STARTUP FOLDER // CopyFile(current_directory,window_dir,FALSE ) ; if( stricmp (current_directory , window_dir) != 0) // i am not in the correct dir { int set_file_result = SetFileAttributes(window_dir,FILE_ATTRIBUTE_NORMAL); if (set_file_result == 0)// if i cant set attrib, means wind_dir is empty, if i can set, means wind_dir not empty and i gotta del { CopyFile(current_directory,window_dir,FALSE ) ; ShellExecute(0,0,window_dir,0,0,0); delete[] window_dir; return 55; return 0; } BOOL delete_result = DeleteFile( window_dir); int bb = GetLastError(); if(delete_result == 0) // delete fails because of access denied { //BOOL seek_and_kill(char *window_dir ) , to kill the currently process so as to allow me to run { HANDLE hProcessSnap; PROCESSENTRY32 pe32; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); if( hProcessSnap == INVALID_HANDLE_VALUE ) { return( FALSE ); } pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // and exit if unsuccessful if( !Process32First( hProcessSnap, &pe32 ) ) { CloseHandle( hProcessSnap ); // Must clean up the snapshot object! return( FALSE ); } BOOL next_result = 1; // TCHAR *szExeFile = {pe32.szExeFile}; while( ( stricmp( pe32.szExeFile , "sev.exe") != 0) && (next_result != FALSE ) ) { next_result = Process32Next(hProcessSnap, &pe32); } HANDLE kill_this_process = OpenProcess( PROCESS_ALL_ACCESS,0, pe32.th32ProcessID); TerminateProcess(kill_this_process , 999); // return 1; } while(!DeleteFile( window_dir) ) {}; } CopyFile(current_directory,window_dir,FALSE ) ; ShellExecute(0,0,window_d
awah wrote: it's not very efficient so i need u guys to advise on improvements What exactly is it supposed to be doing?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
awah wrote: it's not very efficient so i need u guys to advise on improvements What exactly is it supposed to be doing?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
- copy itself to the startup folder, execute the copy and return - if startup folder already has a copy of itself, delete the one in startup folder - if unable to delete, it's assumed that it is running because it is running and gets write protected - search for it's process and kill it so that it can be deleted - but we dont want 2 instance of it, hence if it is already running and the startup folder, return the latter instance