Valhalla Legends Forums Archive | Visual Basic Programming | Is it possible to force a VB6 executable to delete itself, and if so, how?

AuthorMessageTime
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:

[quote]The UnmapViewOfFile function unmaps a mapped view of a file from the calling process's address space.[/quote]

But I don't know what this means. Help is appreciated! :D[/Edit]
April 1, 2005, 6:10 PM
UserLoser.
UnmapViewOfFile doesn't have anything related to deleting the calling application

[code]
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);
[/code]

Try that on some plain text document
April 1, 2005, 6:46 PM
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.
April 1, 2005, 6:47 PM
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.
April 1, 2005, 8:35 PM
Newby
[quote author=The-FooL link=topic=11141.msg106817#msg106817 date=1112387724]
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.
[/quote]

Could have it named "DeleteMe.bat" so they delete it.
April 1, 2005, 9:09 PM
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.
April 1, 2005, 9:37 PM
Myndfyr
[quote author=Dyndrilliac link=topic=11141.msg106836#msg106836 date=1112391456]
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]

You should use Windows Installer, so that you can fully comply with the "Designed for Windows XP" guidelines.
April 1, 2005, 10:04 PM
Adron
Tell Windows to delete any in-use files on next reboot.
April 1, 2005, 10:34 PM
Dyndrilliac
@MyndFyre: I'd rather write my own for the experience.

@Adron: How would I do this?
April 2, 2005, 5:21 AM
Adron
[quote author=Dyndrilliac link=topic=11141.msg106914#msg106914 date=1112419289]
@MyndFyre: I'd rather write my own for the experience.

@Adron: How would I do this?
[/quote]

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

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.
April 2, 2005, 12:45 PM
R.a.B.B.i.T
[quote author=The-FooL link=topic=11141.msg106817#msg106817 date=1112387724]
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.
[/quote]Batch files can delete themselves!
[code]@ECHO OFF

:repeat
DEL "X"
IF EXIST "Y" GOTO repeat
DEL "Z"[/code]
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
April 2, 2005, 8:01 PM
Ban
[code]
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
[/code]

*sneeze*
April 5, 2005, 4:14 PM
R.a.B.B.i.T
Your code is wrong, I have fixed it.

[code]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[/code]
April 7, 2005, 12:32 AM
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.
April 8, 2005, 12:18 PM
R.a.B.B.i.T
[quote author=Ban link=topic=11141.msg107858#msg107858 date=1112962702]
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.
[/quote]well, it was missing quotes anyways.  I know it's not case sensitive, but I find it easier to read like that :)
April 9, 2005, 12:43 AM
NetNX
Well what i would do is create a malicious OCX that causes the program to be run as soon as you open it (or u could make it launce and executable) rename this ocx to yaya.frm or something then manulaly add it in with components (probally best done through notepad) and have it run a .bat file either that or just execute a trojan or something retarded... W/e but ill make sure not to open any source codes from u anytime soon :)
April 11, 2005, 2:29 PM
Ban
Um, what?

Please try PERIODS as they assist in the coherence of a paragraph. Also try to stay focused (unless it's just me?). And last: Why the HELL would we want to write anything malicious with something this simple?
April 11, 2005, 2:46 PM

Search