June 25, 2024, 06:33:49 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Self deleting exe file & path to public folder

Started by Andy, May 15, 2011, 12:39:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

Enjoying IW2 now, does anyone have an example of an .exe file that on completion deletes itself from the disk drive?

IE: program executes, the deletes it's own .exe file from the "C:" drive.

Also,

How do I get the path to the public documents folder (the same location that IW2 installs some files), i have been using this example

CONST CSIDLDESKTOP = 0x0000
CONST CSIDLPROGRAMS = 0x0002
CONST CSIDLCONTROLS = 0x0003
CONST CSIDLPRINTERS = 0x0004
CONST CSIDLPERSONAL = 0x0005
CONST CSIDLFAVORITES = 0x0006
CONST CSIDLSTARTUP = 0x0007
CONST CSIDLRECENT = 0x0008
CONST CSIDLSENDTO = 0x0009
CONST CSIDLBITBUCKET = 0x000a
CONST CSIDLSTARTMENU = 0x000b
CONST CSIDLDESKTOPDIRECTORY = 0x0010
CONST CSIDLDRIVES = 0x0011
CONST CSIDLNETWORK = 0x0012
CONST CSIDLNETHOOD = 0x0013
CONST CSIDLFONTS = 0x0014
CONST CSIDLTEMPLATES = 0x0015
CONST CSIDLCMNSTARTMENU = 0x0016
CONST CSIDLCMNPROGRAMS = 0x0017
CONST CSIDLCMNSTARTUP = 0x0018
CONST CSIDLCMNDESKTOPDIRECTORY = 0x0019
CONST CSIDLAPPDATA = 0x001a
CONST CSIDLPRINTHOOD = 0x001b

DECLARE IMPORT,SHGetSpecialFolderLocation(hwnd as UINT,nFolder as INT,ppITEMIDLIST as POINTER),int
DECLARE IMPORT,SHGetPathFromIDList(pITEMIDLIST:POINTER,PATH:STRING),int
DECLARE IMPORT,CoTaskMemFree(pidl:POINTER)

SUB GetFolderLocation(nFolder:INT),STRING
     DEF path[260]:ISTRING
     DEF pidl:POINTER
     DEF ppidl:POINTER
     ppidl = &pidl
     SHGetSpecialFolderLocation(NULL,nFolder,ppidl)
     SHGetPathFromIDList(pidl,path)
     CoTaskMemFree(pidl)
RETURN path
ENDSUB

but either I have missed it, or it doesn't include the path to the public folder?

Any help would be great,

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

sapero

Hello Andy, this is all in one example:
declare import,SHGetSpecialFolderPathA(int hwndOwner,string lpszPath,int nFolder,int fCreate)
istring path[260]

CONST CSIDL_COMMON_DOCUMENTS = 0x002e
SHGetSpecialFolderPathA(0,path,CSIDL_COMMON_DOCUMENTS,FALSE)
print "common docs: ", path

' delete exe
declare import,GetModuleFileNameA(int module,string path,int size)
GetModuleFileNameA(0,path,260)
print "exe path: ", path
' this is quick&dirty, but will flash a new console window
$if 0
system "cmd", APPEND$("/c del \"", exepath, "\"")
$else
' to hide the console, use another funcion:
declare import,ShellExecuteA(int hwnd,pointer lpOperation,string lpFile,string lpParameters,pointer lpDirectory,INT nShowCmd)
ShellExecuteA(0,0,"cmd", APPEND$("/c del \"", path, "\""), 0, 0)
$endif
' check if deleted ?
declare import,PathFileExistsA(string path),int
print PathFileExistsA(path)?"":"not ", "deleted"

Andy

Hi sapero,

:)

Thanks again for all your help, works well for me!

Just wanted to uninstall my uninstall.exe file when done, excellent.

Thanks again,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.