this doesn't work on winxp but i swear it worked on win98se and win2k when i tested it earlier...
Posted on 2002-03-15 09:02:25 by cynix

this doesn't work on winxp but i swear it worked on win98se and win2k when i tested it earlier...


Cynix,

just from the imports:


GetModuleHandleA
GetModuleFileNameA
CloseHandle
ExitProcess
DeleteFileA
UnmapViewOfFile


I'd say, it uses this way:



#include <windows.h>

int main(int argc, char *argv[])
{
char buf[MAX_PATH];
HMODULE module;

module = GetModuleHandle(0);
GetModuleFileName(module, buf, MAX_PATH);
CloseHandle((HANDLE)4);

__asm
{
lea eax, buf
push 0
push 0
push eax
push ExitProcess
push module
push DeleteFile
push UnmapViewOfFile
ret
}

return 0;
}



right? :grin:
Posted on 2002-03-15 10:42:38 by bazik
I compiled and disassembled that to make an external delete procedure in a seperate object file that works in Windows 2000.
Posted on 2002-03-15 12:56:31 by roaknog
On windows XP if a batch file deletes itself, CMD.EXE just displays, batch file cannot be found and exit.

For Example:


echo Self Deleting batch file
pause

del c:\build\batch.bat

echo Deleted, time to exit
pause > nul



The output:


C:\build>batch

C:\build>echo Self Deleting batch file
Self Deleting batch file

C:\build>pause
Press any key to continue . . .

C:\build>del c:\build\batch.bat
The batch file cannot be found.


-huh
Posted on 2002-03-15 15:53:20 by huh



Cynix,

just from the imports:


GetModuleHandleA
GetModuleFileNameA
CloseHandle
ExitProcess
DeleteFileA
UnmapViewOfFile


I'd say, it uses this way:



#include <windows.h>

int main(int argc, char *argv[])
{
char buf[MAX_PATH];
HMODULE module;

module = GetModuleHandle(0);
GetModuleFileName(module, buf, MAX_PATH);
CloseHandle((HANDLE)4);

__asm
{
lea eax, buf
push 0
push 0
push eax
push ExitProcess
push module
push DeleteFile
push UnmapViewOfFile
ret
}

return 0;
}



right? :grin:
right :alright:

wonder why it doesn't work on xp but ok on 2k...
Posted on 2002-03-15 23:12:10 by cynix
Fake,

Dirty is by far the more fun ... just gotta find a way that'll run cross-windows.

Dirty is fun, but I hate when people use dirty stuff in production
code. It just isn't an option in commercial code.

Cyrix,

wonder why it doesn't work on xp but ok on 2k...

Because it's dirty.

Huh,

On windows XP if a batch file deletes itself, CMD.EXE just displays, batch file cannot be found and exit.

As I already said, NT based windows versions by default close
the console windows on program termination. Not so with 9x.
Posted on 2002-03-16 05:25:38 by f0dder
I know you could use a DOS com file to delete itself but its been years since I did stuff like that. Store the COM file in the EXE file, write it to disk, run it as the last statement with WinExec() or similar and have it delete the disk file and then itself.

I don't know if Windows SHARE would allow this but it worked fine in DOS.

Regards,

hutch@movsd.com
Posted on 2002-03-16 06:14:36 by hutch--
A .com still opens a console window, which would stick under 9x :/
Posted on 2002-03-16 06:22:46 by f0dder
Yep,

Nothing like a bit of good old dos Quick Basic to do the job.


'---------------------
' trashit.exe
CLS
IF COMMAND$ <> "" THEN
KILL COMMAND$
END IF
KILL "trashit.exe"
'---------------------

In your own code, write trashit.exe to disk, run the LAST function call as,

rv = WinExec("trashit.exe yourfile.exe",1)

Wulla (Australian for Voila) it magically disappears by itself. Tested on win95b. Dunno about later M$ OS versions.

If I can find the old DOS libraries for PDQ, I will do a small EXE for it, this one in standard QB4.5 is 20k which is too big.

Regards,

hutch@movsd.com
Posted on 2002-03-16 06:38:01 by hutch--
whats about this :
you can check first what version of win is running and for win9x you can close the batch (winoldap) with this:
cls
@exit
or why not use the registry key runonce and set a key to del the file ?
after next winstart the file and key is deletet.

aehm...if you use a deinstaller you can copy your deinstaller to windows\Temporary Internet Files
most users have selected to del this folder automatical ,to get shure its set you can set the registry key to del this folder.
so at last the deinstaller is also gone :)

bye
Posted on 2002-03-16 06:48:00 by syntax_error
Here is a file that self deletes in win95 using the proviously mentioned technique. You still see the console window from the DOS file but as its called with WinExec() directly and not from command.com, it closes by itself.

Regards,

hutch@movsd.com
Posted on 2002-03-16 06:52:40 by hutch--

you can check first what version of win is running and for win9x you can close
the batch (winoldap) with this:
cls
@exit

That's a bit hard to do after you delete the batch file ;).


aehm...if you use a deinstaller you can copy your deinstaller to
windows\Temporary Internet Files most users have selected to del
this folder automatical ,to get shure its set you can set the registry
key to del this folder.

*most* users? I doubt it :). Many users perhaps, but probably a drop
in the water compared to the total windows installations. Better to
use the normal temp folder, and MoveFileEx (NT) or wininit.ini or registry
(9x).
Posted on 2002-03-16 06:54:52 by f0dder

aehm...if you use a deinstaller you can copy your deinstaller to windows\Temporary Internet Files
most users have selected to del this folder automatical ,to get shure its set you can set the registry key to del this folder.
so at last the deinstaller is also gone :)

bye



I use Mozilla, wich doesn't use this folder :)
Posted on 2002-03-16 07:30:53 by bazik
Or you could just adapt for each OS family; Create a tempory EXE with FILE_FLAG_DELETE_ON_CLOSE and use that to do any last cleanups for 9x. For NT use a batch file.

:)
Posted on 2002-03-16 21:47:52 by huh
I remember all the methods were described by Jefry Richter in MSJ in 1996.
I tried them with NT 4 SP 3. And only one worked (remove after reboot)
If you like you can try it on your OS and report wich method(s) work on your OS.
Here is zip with his prog.
You can unzip it, try one method, if it works unzip again, try another and so on.
Posted on 2002-05-22 12:55:00 by The Svin
Have a look at http://www.anticracking.sk/EliCZ/export/DelMod.zip .
Haven't tested it, but it probably works... looks pretty messy though,
I still prefer leaving a small exe in the user temp dir and have it
deleted on next reboot.
Posted on 2002-05-22 15:40:35 by f0dder
I did :)
I usually check all that Radim writes.
Why you call it messy? IMHO he has a stylish way in his code.
Posted on 2002-05-22 17:43:22 by The Svin
it's not his code style that's messy, it's quite fine... but it's the "assumptions".
It's probably not very likely that NT will be using LDT anytime soon,
but I still prefer GetVersion(Ex). Also, unmapping your own executable... ok, he's
doing it from a DLL, but I dunno how 'clean' it feels :). While it's perhaps not
very likely that EliCZ' code will ever break, I feel more comfortable sticking a
small (lets say 16k, probably overkill) "do the final cleanup" exe in the user
temp dir, and flag it for deletion on next reboot. It's a lot less to leave behind
than most of the install systems out there, and should be guaranteed to work on all
win32 versions.
Posted on 2002-05-22 18:02:26 by f0dder
You can do it without need of temp directory. There might be ocasions when it's not cleaned after reboot.
With MoveFileEx. Documented and works on all Wins.
The problem universal reliable method to remove immideatly.
Posted on 2002-05-22 19:37:59 by The Svin

You can do it without need of temp directory. There might be ocasions when
it's not cleaned after reboot.

Well, I prefer the temp directory approach since that allows me to delete
the installation folder of my app. Ie, spawn the small final-cleanup app,
remove all installed files, then take whatever action necessary to get
rid of the tempfile.


With MoveFileEx. Documented and works on all Wins.

Hm, PlatformSDK says MoveFileEx is not suppoted on 9x - is this wrong?


The problem universal reliable method to remove immideatly

Yes. I don't know of any "clean" way to do it, unfortunately. Perhaps
something in the microsoft installer SDK?
Posted on 2002-05-22 19:43:02 by f0dder