My self install codes using startup folder - please comment

This is a discussion on My self install codes using startup folder - please comment within the C++ Programming forums, part of the General Programming Boards category; guys here are my self install codes for any applications it will copy itself to the startup folder and run ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    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


    Code:
    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_dir,0,0,0);
    		delete[] window_dir;
    		return 55;
    
    	}
    	else // else if i am in the correct dir, i dont want 2 instance of the same thing
    	{
    		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;
    		BOOL duplicate = FALSE;
     // TCHAR *szExeFile = {pe32.szExeFile};
      
    		while(   next_result != FALSE )
    		{
    			if(  (stricmp( pe32.szExeFile , "sev.exe") == 0)   &&(duplicate == TRUE))
    			{
    				return 55;
    			}
    			if( ( stricmp( pe32.szExeFile , "sev.exe") == 0)    &&(duplicate == FALSE))
    			{
    				duplicate = TRUE;
    			}
    			next_result = Process32Next(hProcessSnap, &pe32);
    		}
    					
    			
    			if(  (stricmp( pe32.szExeFile , "sev.exe") == 0)   &&(duplicate == TRUE))
    			{
    			//	return 55;
    			}
    }	
    	delete[] window_dir;
    	delete[] current_directory;

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    114
    - 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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 10:52 PM
  2. Startup using STARTUP folder method for winXP & win98
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 05-26-2005, 05:59 AM
  3. Hiding a folder
    By nextstep in forum Windows Programming
    Replies: 16
    Last Post: 03-20-2005, 03:07 PM

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