Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. My self install codes using startup folder - please comment

My self install codes using startup folder - please comment

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    awah
    wrote on last edited by
    #1

    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

    Y D 2 Replies Last reply
    0
    • A awah

      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

      Y Offline
      Y Offline
      Yulianto
      wrote on last edited by
      #2

      Write an article for it.


      Work hard, Work effectively.

      1 Reply Last reply
      0
      • A awah

        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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • D David Crow

          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

          A Offline
          A Offline
          awah
          wrote on last edited by
          #4

          - 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups