WWW.ИСХОДНИКИ.РУ cpp.sources.ru
java.sources.ru web.sources.ru soft.sources.ru
jdbc.sources.ru asp.sources.ru api.sources.ru

  Форум на исходниках
  C / C++ / Visual C++
  как удалить екзешник из самого себя

СПРОСИТЬ  ОТВЕТИТЬ
профайл | регистрация | faq

Автор Тема:   как удалить екзешник из самого себя
unforgiven_qwerty опубликован 07-02-2002 09:28 MSK   Click Here to See the Profile for unforgiven_qwerty   Click Here to Email unforgiven_qwerty  
народ подскажите как удалить екзешник из самого себя. Подскажите хотя бы в каком направленни мыслить (функции и т д)
sleeps опубликован 07-02-2002 10:31 MSK     Click Here to See the Profile for sleeps  Click Here to Email sleeps     
расшишруй
ADK опубликован 07-02-2002 10:33 MSK     Click Here to See the Profile for ADK  Click Here to Email ADK     
где-то встречал в Сети. Там использовалась извращенская методика создания скрытого консольного процесса и выполнения командного файла.
al опубликован 07-02-2002 11:58 MSK     Click Here to See the Profile for al  Click Here to Email al     
См. в MSDN описание функции MoveFileEx
Molibden опубликован 07-02-2002 00:53 MSK     Click Here to See the Profile for Molibden  Click Here to Email Molibden     
MoveFileEx - это для Win2K :( Для себя нашёл самый оптимальный вариант - через wininit.ini при перезагрузке.
stan опубликован 07-02-2002 00:54 MSK     Click Here to See the Profile for stan  Click Here to Email stan     
Была статья в MSDN про это. Суть решения - запускаегь .bat файл, который удаляет экзешник и самого себя
gonzales опубликован 07-02-2002 16:38 MSK     Click Here to See the Profile for gonzales  Click Here to Email gonzales     
Помню недавно наезжали на GE за
пусылание на ... MSDN и поэтому если у тебя
его нет держи технологию

I discussed how to write an unsetup program that was able to delete itself from the disk in my January 1996 Win32® Q&A column, and I presented three techniques for making an application delete itself. A reader recently suggested another technique that I'd like to share with you. I have tested this technique only on Windows NT®, but I believe that it will also work on Windows® 95. Figure 1 shows the code.
The technique works as follows: when the program wants to delete itself, it first copies the EXE file on the disk to the user's temporary directory. I call this copy the clone. Then the program calls CreateFile to open the cloned EXE file. The call to CreateFile passes the FILE_FLAG_DELETE_ ON_CLOSE option. This tells the operating system to delete the file when it is closed (I'll come back to this later). Finally, the original EXE file spawns this cloned version of the EXE, passing it two command-line arguments. The first argument is the inheritable handle of the original process, and the second is the full path name of the original EXE file. After spawning the cloned version, the original EXE file simply terminates.
At this point, the cloned version of the EXE file (located in the user's temporary directory) starts running. This version examines its command-line arguments and detects that it is not the original version but the cloned version. The cloned version extracts the process handle to the original EXE file and waits for the original process to terminate. Once the original process has terminated, the cloned process can delete the EXE file image. This, of course, gives you the desired effect of deleting the EXE file that was running. But what about deleting the cloned EXE file that was copied to the user's temporary directory? Because the cloned EXE file was opened by the original EXE with the FILE_FLAG_ DELETE_ON_CLOSE flag, the operating system will delete the cloned EXE file automatically when it terminates. Nothing could be easier.


SUnteXx опубликован 08-02-2002 00:30 MSK     Click Here to See the Profile for SUnteXx  Click Here to Email SUnteXx     
Есть пример на апях! Нужен? Мыль на SUnteXx@pisem.net!)
the_moon опубликован 08-02-2002 07:17 MSK     Click Here to See the Profile for the_moon  Click Here to Email the_moon     
Привет

а может, сбросить на диск BATCH файл
с DEL KAMIKADZE.EXE

а потом запустить его с помощью exec. Я тут вот что вычитал.

When a call to an _exec function is successful, the new process is placed in the memory previously occupied by the calling process.

Тоесть вызывающий процесс умирает, и EXE файл вроде как должен освободится. Не пробывал, не буду врать.

klep опубликован 08-02-2002 13:20 MSK     Click Here to See the Profile for klep  Click Here to Email klep     
2gonzales:

все конечно хорошо но вот одно не понятно.

FILE_FLAG_DELETE_ON_CLOSE
Indicates that the operating system is to delete the file immediately after all of its handles have been closed, not just the handle for which you specified FILE_FLAG_DELETE_ON_CLOSE.

У меня файл сразу же удаляется
так как не один хандл на него не ссылается.
Как с этим быть?


HANDLE hInFile = CreateFile(TmpPath2.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);

if(hInFile == NULL)
{
Application->MessageBox("can't open [$Tmp$] file","Error",MB_OK+MB_ICONERROR);
}

CloseHandle(hInFile);

SUnteXx опубликован 08-02-2002 16:04 MSK     Click Here to See the Profile for SUnteXx  Click Here to Email SUnteXx     
Вам же сказали. ЕСТЬ РАБОТАЮЩИЙ ПРИМЕР! КОМУ НАДО (2 людям точно) КИНУ СОРС! Что тут спорить!

Создается файл с расширением *.bat, в него прописывается следующий текст:

del \"ПУТЬ_К_ЕХЕ\n\
:Repeat\n\
del \"ПУТЬ_К_ЕХЕ\"\n\
if exist \"ПУТЬ_К_ЕХЕ\" goto Repeat\n\
:Repeat1\n\
del \"ПУТЬ_К_ВАТ\"\n\

Создали файл, прописали текст, запустили файл (в нем бесконечный цикл, пока файл существует - пробовать удалить себя:), кильнули себя (т.е. закрыли нашу прогу). Прога закрывается, убираются все следы:)

Вот и вся любовь:)

klep опубликован 08-02-2002 17:31 MSK     Click Here to See the Profile for klep  Click Here to Email klep     
с использованием BAT'ника - не интересует ( к тому же я уже качал такой исходник)

интересует с
FILE_FLAG_DELETE_ON_CLOSE.

смотреть пост выше!

gonzales опубликован 09-02-2002 22:17 MSK     Click Here to See the Profile for gonzales  Click Here to Email gonzales     
Может проблема в
Subsequent open requests for the file will fail, unless FILE_SHARE_DELETE is used.
tonik опубликован 10-02-2002 03:22 MSK     Click Here to See the Profile for tonik  Click Here to Email tonik     
Там же ясно написано:
1. Создать копию экзешника.
2. Открыть созданную копию функцией CreateFile с указанием FILE_FLAG_DELETE_ON_CLOSE.
3. Запустить созданную копию (создать из неё процесс).
4. ПОСЛЕ ЗАПУСКА закрыть полученный в п.2 описатель.
5. Завершить процесс (при этом автоматически выполнится п.4).
6. Когда процесс из копии экзешника отработает, Windows удалит эту копию из-за FILE_FLAG_DELETE_ON_CLOSE.

Я вчера попробовал, и всё прекрасно заработало, поэтому большое спасибо, gonzales!!!

СПРОСИТЬ  ОТВЕТИТЬ
Перейти:


E-mail | WWW.ИСХОДНИКИ.RU

Powered by: Ultimate Bulletin Board, Freeware Version 5.10a
Purchase our Licensed Version- which adds many more features!
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 2000.