[RESOLVED] Copy or move .exe file when it runs
Hai,
I need to copy or move executable file when it starts execute!
My code: (My exe name here: test.exe)
Code:
copystr = "copy " + Chr(34) & App.Path & "\" & "test.exe" & Chr(34) + " " + Chr(34) & Environ("windir") & "\test.exe" + Chr(34) + " /Y"
test = Shell(copystr, vbHidden)
Above code doesn't work for me!
When "test.exe" start execute i need to move "test.exe" to specified location!
how to achieve?
Advance thanks!
Re: Copy or move .exe file when it runs
Try this :
dim SourcePath as string
dim DestinationPath as string
SourcePath = App.Path & "\" & App.EXEName & ".exe"
'To keep it on the same location
'DestinationPath = App.Path & "\" & "CopiedFile" & ".exe"
'To change it's location then use this :
DestinationPath = Environ("windir") & "\" & App.EXEName & ".exe"
FileCopy SourcePath , DestinationPath
Re: Copy or move .exe file when it runs
Quote:
Originally Posted by
kpmsivachand
I need to copy or move executable file when it starts execute!
Why do you need to do that?
Re: Copy or move .exe file when it runs
Quote:
Originally Posted by
justgreat
Try this :
dim SourcePath as string
dim DestinationPath as string
SourcePath = App.Path & "\" & App.EXEName & ".exe"
'To keep it on the same location
'DestinationPath = App.Path & "\" & "CopiedFile" & ".exe"
'To change it's location then use this :
DestinationPath = Environ("windir") & "\" & App.EXEName & ".exe"
FileCopy SourcePath , DestinationPath
It doesn't work, it give same error "File not found!"
Even though file exist, (bcz it running!)
Re: Copy or move .exe file when it runs
Quote:
Originally Posted by
RhinoBull
Why do you need to do that?
I want to run my application from one particular location, Even though the location modified!
I guess i need to load exe to memory and move
Any help can be appreciated
Re: Copy or move .exe file when it runs
You haven't given a reason why you want to "copy or move executable file", and certainly not given any valid reason for trying to put your files in to the Windows folder (which is only meant for use by Windows itself).
Re: Copy or move .exe file when it runs
Quote:
Originally Posted by
kpmsivachand
It doesn't work, it give same error "File not found!"
Even though file exist, (bcz it running!)
Even if the file is running filecopy works, but it seems your copiying it to the same directory with the same name !
Or that you are getting a wrong path for windir !!
The code i gave you works 100%!
I second the others, why you want to do this ? smells your making a hidden program from user ?
Re: Copy or move .exe file when it runs
Quote:
Originally Posted by
si_the_geek
You haven't given a reason why you want to "copy or move executable file", and certainly not given any valid reason for trying to put your files in to the Windows folder (which is only meant for use by Windows itself).
Excuse me!
I gave sample path like that but not exactly, i ll use different path only! now can u give me suggestions???:rolleyes:
Re: Copy or move .exe file when it runs
No, because you haven't answered the most important question yet... why do you want to do this?
The best way to achieve things varies greatly based on why you are doing them, and not every possible method is apt, and many are far from ideal - which is the reason you have repeatedly been asked why you want to do it.
As you have put so much effort in to not answering, it implies heavily that you have malicious intentions... so if you don't give a reasonable answer, I will close this thread.
Re: Copy or move .exe file when it runs
Quote:
Originally Posted by
justgreat
Even if the file is running filecopy works, but it seems your copiying it to the same directory with the same name !
Or that you are getting a wrong path for windir !!
The code i gave you works 100%!
Yes mate, i had little mistake, your code works perfectly!
Thanks for resolving! BTW I gave sample path of windows, but u guys meant wrongly any of my problem solved!
Re: [RESOLVED] Copy or move .exe file when it runs
Quote:
Originally Posted by
kpmsivachand
... but u guys meant wrongly any of my problem solved!
So why are you afraid to answer our question then? :rolleyes:
Quote:
Originally Posted by
RhinoBull
Why do you need to do that?
Quote:
Originally Posted by
si_the_geek
No, because you haven't answered the most important question yet... why do you want to do this?
I am very curios about what is it that you do. Thanks.
Re: [RESOLVED] Copy or move .exe file when it runs
Quote:
Originally Posted by
RhinoBull
So why are you afraid to answer our question then? :rolleyes:
I am very curios about what is it that you do. Thanks.
ah i am not afraid to answer and all(Due to drizzle)! I developing the application called "pen drive virus blocker", while installing this, getting the path where to execute. It need to execute only from tht location due to other components tie-up. So i don't want to miss use this application when it is executed away from specified location and getting the "Error: File not found!"(Due to other components tie-up"). So that if it happen i move executable to the specified location and runs smoother!
Thanks!!!
Re: [RESOLVED] Copy or move .exe file when it runs
There is nothing in that explanation that actually justifies moving/copying the executable file - there are simpler ways of achieving the same end result, and they wont get your program treated as malware either.
We don't know enough details to give complete solutions, but in simple terms you could alter the code that reads the files (there is no valid reason to need them in the same location as the executable file, just specify the location along with the file name). That would also reduce issues caused by other things, such as someone altering the shortcut to your program, or a component you use (such as a CommonDialog) automatically altering the Current Working Directory.