|
-
Dec 11th, 2009, 09:12 AM
#1
Thread Starter
Addicted Member
[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!
-
Dec 11th, 2009, 09:20 AM
#2
Hyperactive Member
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
Last edited by justgreat; Dec 11th, 2009 at 09:32 AM.
-
Dec 11th, 2009, 10:04 AM
#3
Re: Copy or move .exe file when it runs
 Originally Posted by kpmsivachand
I need to copy or move executable file when it starts execute!
Why do you need to do that?
-
Dec 11th, 2009, 10:30 AM
#4
Thread Starter
Addicted Member
Re: Copy or move .exe file when it runs
 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!)
-
Dec 11th, 2009, 10:33 AM
#5
Thread Starter
Addicted Member
Re: Copy or move .exe file when it runs
 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
-
Dec 11th, 2009, 10:54 AM
#6
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).
-
Dec 11th, 2009, 11:37 AM
#7
Hyperactive Member
Re: Copy or move .exe file when it runs
 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 ?
-
Dec 11th, 2009, 12:17 PM
#8
Thread Starter
Addicted Member
Re: Copy or move .exe file when it runs
 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???
-
Dec 11th, 2009, 12:26 PM
#9
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.
-
Dec 11th, 2009, 12:26 PM
#10
Thread Starter
Addicted Member
Re: Copy or move .exe file when it runs
 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!
-
Dec 11th, 2009, 02:34 PM
#11
Re: [RESOLVED] Copy or move .exe file when it runs
 Originally Posted by kpmsivachand
... but u guys meant wrongly any of my problem solved!
So why are you afraid to answer our question then? 
 Originally Posted by RhinoBull
Why do you need to do that?
 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.
-
Dec 11th, 2009, 06:15 PM
#12
Thread Starter
Addicted Member
Re: [RESOLVED] Copy or move .exe file when it runs
 Originally Posted by RhinoBull
So why are you afraid to answer our question then?
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!!!
Last edited by kpmsivachand; Dec 11th, 2009 at 06:28 PM.
-
Dec 12th, 2009, 08:36 AM
#13
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|