Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selfmoving ?
#12
Function exemove
Code:
Copy      Help
;note: the main function of the exe must be function, not macro.
;note: this function should be called somewhere at the beginning of the main function, not on WM_INITDIALOG.


str myExe=ExeFullPath
;out myExe
str correctFolder.expandpath("$desktop$\My Files")
str correctExe.from(correctFolder "\" _s.getfilename(myExe 1))

if myExe~correctExe ;;I am in correct folder
,;what is my command line?
,str s
,if !empty(_command) and findrx(_command "/del ''(.+?)''" 0 1 s 1)
,,;my command line tells me to delete that incorrect exe
,,1 ;;wait until that incorrect exe's process ends
,,del- s; err out "Failed to delete %s" s
,,mes "File moved to folder ''My Files'' on desktop. "
,,end ;;maybe this is not needed
else ;;I am somewhere else
,;copy me to correct folder; cannot move or delete me now, because i'm running.
,mkdir correctFolder
,cop- myExe correctFolder
,;run me from correct folder and pass command line that tells to delete me
,str cmdLine.format("/del ''%s''" myExe)
,run correctExe cmdLine
,;exit
,end

Function ExeFullPath
Code:
Copy      Help
;/
function~

;Returns full path of this exe file.
;If you need only path without filename, instead use special variable _qmdir, or str s.expandpath("$qm$\").


BSTR b.alloc(300)
GetModuleFileNameW(0 b 300)
_s.ansi(b)
_s.dospath(_s 1)
_s.lcase
ret _s


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)