Is it possible to copy the file that is running to another location (back it up)?

If so, could somone please point me in the right direction? I am a newbie, so be gentle! ;)


Posted on 2004-11-14 21:16:45 by TropE
yes you just need to know where the file is on the harddrive.
the path to the file that is runing. basically.

if you know the path for the file just copy it with CopyFile()
if not, you need to get the process list, find the runing process that you want to copy, get the path to the executable, and thats your file. just copy it.

if you need to list processes and find the path to executable, you need to search for info on ToolHelp32 apis.. i dont have any links off the head right now, so just snoop around.
have fun.
Posted on 2004-11-14 21:42:16 by pwn
invoke GetModuleHandle, 0h
invoke GetModulFileName, eax, bff, 260d
invoke CopyFile, bff, backupfile, FALSE

Posted on 2004-11-15 06:43:56 by Dom
This doesn't appear to work:


newFileName db "Backup.exe"
thisFileName db ?

invoke GetModuleHandle, 0h
invoke GetModuleFileName, eax, thisFileName, 260d
invoke CopyFile, thisFileName, newFileName, FALSE
invoke ExitProcess, NULL


end start
Posted on 2004-11-15 15:57:41 by TropE
newFile db 'backup.exe', 0h

hInst dd ?

ThisFile db 260d dup(?)

invoke GetModuleHandle, 0h
mov hInst, eax

invoke GetModuleFileName, hInst, addr ThisFile, 260d
invoke CopyFile, addr ThisFile, addr newFile, FALSE
invoke ExitProcess, 0h
end Main
Posted on 2004-11-16 03:21:57 by Dom
This is courtesy of Vortex! Thanks!

;VERY IMPORTANT!!! Save and assemble this source file with a name different than "Backup.exe"
; I choosed the name as "trial.exe"

.model flat,stdcall
option casemap:none

include \masm32\include\
include \masm32\include\

includelib \masm32\lib\kernel32.lib


newFileName db "Backup.exe"


thisFileName db 260 dup(?) ; 260 bytes reserved to get the name of the current module

start: ; Here you should put the entry of your code

invoke GetModuleHandle, NULL
invoke GetModuleFileName,eax,ADDR thisFileName, 260 ; use the ADDR operator to point the filenames
invoke CopyFile, ADDR thisFileName, ADDR newFileName,FALSE ; thisFileName and newFileName are stored in uninitialized
; and initialized data sections respectively.

invoke ExitProcess, NULL ; Now, trial.exe should be copied as backup.exe to the
; current directory.

end start

Posted on 2004-11-16 07:38:58 by TropE