Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1424 connectés 

  FORUM HardWare.fr
  Programmation

  Comment effacer un EXE en cours d'utilisation ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment effacer un EXE en cours d'utilisation ?

n°27924
slashp
Posté le 27-04-2001 à 01:21:40  profilanswer
 

Salut,
 
Je suis en train de programmer un désinstalleur pour un logiciel que je développe, et je voudrait que le désinstalleur, supprime les fichiers du logiciel, ainsi que lui-même, comment faire, car le désinstalleur étant en cours d'éxecution Windows interdit sa suppression.
 
Merci

mood
Publicité
Posté le 27-04-2001 à 01:21:40  profilanswer
 

n°27932
gnoof
Posté le 27-04-2001 à 08:05:40  profilanswer
 

Tiens voilà un bout de code qui créer un executable qui s'effaceras à sa fermeture. Il repose sur l'utilisation du flag  
FILE_FLAG_DELETE_ON_CLOSE pour la fonction CreateFile.
Ce code n'est pas de moi.
**************************************************************
 Module name: DeleteMe.cpp
 Written by: Jeffrey Richter
 Description: Allows an EXEcutable file to delete itself
 ********************************************************************/
 
 #include <Windows.h>
 #include <stdlib.h>
 #include <tchar.h>
 
 /////////////////////////////////////////////////////////////////////
 
 int WINAPI WinMain(HINSTANCE h, HINSTANCE h2, LPSTR psz, int n) {
 
    // Is this the original EXE or the clone EXE?
    // If the command-line 1  argument, this is the original EXE
    // If the command-line >1 argument, this is the clone EXE
    if (__argc == 1) {
 
       // Original EXE: Spawn clone EXE to delete this EXE
 
       // Copy this EXEcutable image into the user's temp directory
       TCHAR szPathOrig[_MAX_PATH], szPathClone[_MAX_PATH];
       GetModuleFileName(NULL, szPathOrig, _MAX_PATH);
       GetTempPath(_MAX_PATH, szPathClone);
       GetTempFileName(szPathClone, __TEXT("Del" ), 0, szPathClone);  
       CopyFile(szPathOrig, szPathClone, FALSE);
 
       // Open the clone EXE using FILE_FLAG_DELETE_ON_CLOSE
       HANDLE hfile = CreateFile(szPathClone, 0, FILE_SHARE_READ, NULL,                            
 OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
 
       // Spawn the clone EXE passing it our EXE's process handle
       // and the full path name to the original EXE file.
       TCHAR szCmdLine[512];
       HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE,                                          
 GetCurrentProcessId());
       wsprintf(szCmdLine, __TEXT("%s %d \"%s\"" ), szPathClone, hProcessOrig,                  
 szPathOrig);
       STARTUPINFO si;
       ZeroMemory(&si, sizeof(si));
       si.cb = sizeof(si);
       PROCESS_INFORMATION pi;
       CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
       CloseHandle(hProcessOrig);
       CloseHandle(hfile);
 
       // This original process can now terminate.
       } else {
 
       // Clone EXE: When original EXE terminates, delete it
       HANDLE hProcessOrig = (HANDLE) _ttoi(__targv[1]);
       WaitForSingleObject(hProcessOrig, INFINITE);
       CloseHandle(hProcessOrig);
       DeleteFile(__targv[2]);
       // Insert code here to remove the subdirectory too (if desired).
 
       // The system will delete the clone EXE automatically  
       // because it was opened with FILE_FLAG_DELETE_ON_CLOSE
    }
    return(0);
 }

n°27939
slashp
Posté le 27-04-2001 à 09:19:52  profilanswer
 

Merci


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  Comment effacer un EXE en cours d'utilisation ?

 

Sujets relatifs
ou trouver des cours de c++ builder pour directX ou openGl[HTML] Comment lancer un EXE sans msg box ???
VBA Excel: recuperer le chemin(PATH) du fichier en coursutilisation et travail sur des fichier .wav sous java 1.3
Utilisation du net send sous Nt4 ou win2k[OpenGL] Utilisation d'objets créés avec 3D Exploration
utilisation JRE et java Urgent!!Cours en corba - environement TAO???
[VBS] Cherche cours sur le net[PHP] comment effacer tous ce qui se trouve entre deux caratcères ?
Plus de sujets relatifs à : Comment effacer un EXE en cours d'utilisation ?


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR