• Welcome to Valhalla Legends Archive.
 

Is it possible to force a VB6 executable to delete itself, and if so, how?

Started by Dyndrilliac, April 01, 2005, 12:10 PM

Previous topic - Next topic

Dyndrilliac

I tried searching for 'allintext: visual basic forcing OR executable "delete itself"', but couldn't find it. Can anyone shed light into this subject for me? I saw a few things about C++ talking about setting the UnMapViewOfFile or something similar, but I don't know what this is or if it applies to VB.

[Edit]Ok, MSDN says:

QuoteThe UnmapViewOfFile function unmaps a mapped view of a file from the calling process's address space.

But I don't know what this means. Help is appreciated! :D[/Edit]
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

UserLoser.

UnmapViewOfFile doesn't have anything related to deleting the calling application


HANDLE File = CreateFile(...)
HANDLE FileMapping = CreateFileMapping(File, ...)
BYTE *FileData = (BYTE*)MapViewOfFile(FileMapping, ...)
printf("Our file data:\r\n%s\r\n", FileData);
CloseHandle(File)
CloseHandle(FileMapping)
UnmapViewOfFile(FileData);


Try that on some plain text document

Newby

Hmm. This does sound confusing.

I'd say copy the current directory to a registry key (anywhere), copy the program itself to a temporary directory (or maybe a batch file?), spawn the program (batch file?), have it read the directory your program is in from the registry, and delete it.

It's a long way around it, but hey, that's off the top of my head.

And btw, UnmapViewOfFile is useless.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

The-FooL

You could use a batch file, like newbie said.  Create the batch file, and run it(to terminate the exe).  But then you are left with a batch file.

Newby

Quote from: The-FooL on April 01, 2005, 02:35 PM
You could use a batch file, like newbie said.  Create the batch file, and run it(to terminate the exe).  But then you are left with a batch file.

Could have it named "DeleteMe.bat" so they delete it.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Dyndrilliac

Well, I'm trying to find a way to delete the executable and not leave anything. I guess the problem is, I need to delete a file while it's in use without any outside stuff. It's for an uninstaller I'm making.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

MyndFyre

Quote from: Dyndrilliac on April 01, 2005, 03:37 PM
Well, I'm trying to find a way to delete the executable and not leave anything. I guess the problem is, I need to delete a file while it's in use without any outside stuff. It's for an uninstaller I'm making.

You should use Windows Installer, so that you can fully comply with the "Designed for Windows XP" guidelines.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Adron


Dyndrilliac

@MyndFyre: I'd rather write my own for the experience.

@Adron: How would I do this?
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Adron

Quote from: Dyndrilliac on April 01, 2005, 11:21 PM
@MyndFyre: I'd rather write my own for the experience.

@Adron: How would I do this?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/movefileex.asp

And it would probably be a more useful experience to learn how to program a windows installer package. It's not that easy, writing your own simple copy-all-files installer app might well be as easy or easier. Except you won't get everything right, as you would if you made a windows installer package.

R.a.B.B.i.T

Quote from: The-FooL on April 01, 2005, 02:35 PM
You could use a batch file, like newbie said.  Create the batch file, and run it(to terminate the exe).  But then you are left with a batch file.
Batch files can delete themselves!
@ECHO OFF

:repeat
DEL "X"
IF EXIST "Y" GOTO repeat
DEL "Z"

X is the full path to the executable (IE: App.Path & "\" & App.Name & ".exe")
Y is the executable name and extention (IE: App.Name & ".exe")
Z is the batch file (IE: "del.bat") if in the same directory as the executable, or the full path if not

Ban


REM *Ban pokes Newby*

Open "KillMe.bat" For Output As #1
Print #1, "@echo off"
Print #1, echo roflwaffles!
Print #1, "set appPath=" & chr(34) & App.Path & "\" & App.exename & chr(34)
Print #1, "a_check:"
Print #1, "DEL appPath"
Print #1, "IF EXIST appPath GOTO a_check"
Print #1, "DEL KillMe.bat"

Close #1


*sneeze*

R.a.B.B.i.T

Your code is wrong, I have fixed it.

REM *Ban pokes Newby*

Open "KillMe.bat" For Output As #1
Print #1, "@echo off"
'Print #1, "echo roflwaffles!"  ' needed quotes, also "@echo off" only turns off command echoing, echo as a command still outputs
Print #1, "set appPath=" & chr(34) & App.Path & "\" & App.exename & chr(34)
Print #1, "a_check:"
Print #1, "DEL %appPath" ' need "%" to denote variable
Print #1, "IF EXIST %appPath GOTO a_check" ' same
Print #1, "DEL KillMe.bat"

Close #1

Ban

Tis not case sensitive :)

But yeah, whipped that up in about 10 seconds while at school, but thanks for pointing out my simple syntax errors ;)

btw I already know what @echo off did.
It makes it non-fugly.

R.a.B.B.i.T

Quote from: Ban on April 08, 2005, 07:18 AM
Tis not case sensitive :)

But yeah, whipped that up in about 10 seconds while at school, but thanks for pointing out my simple syntax errors ;)

btw I already know what @echo off did.
It makes it non-fugly.
well, it was missing quotes anyways.  I know it's not case sensitive, but I find it easier to read like that :)