Results 1 to 13 of 13

Thread: [RESOLVED] Copy or move .exe file when it runs

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Resolved [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!

  2. #2
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    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.

  3. #3

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Copy or move .exe file when it runs

    Quote Originally Posted by justgreat View Post
    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!)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Copy or move .exe file when it runs

    Quote Originally Posted by RhinoBull View Post
    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

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  7. #7
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: Copy or move .exe file when it runs

    Quote Originally Posted by kpmsivachand View Post
    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 ?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Copy or move .exe file when it runs

    Quote Originally Posted by si_the_geek View Post
    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???

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Thumbs up Re: Copy or move .exe file when it runs

    Quote Originally Posted by justgreat View Post
    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!

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] Copy or move .exe file when it runs

    Quote Originally Posted by kpmsivachand View Post
    ... but u guys meant wrongly any of my problem solved!
    So why are you afraid to answer our question then?

    Quote Originally Posted by RhinoBull View Post
    Why do you need to do that?
    Quote Originally Posted by si_the_geek View Post
    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.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Arrow Re: [RESOLVED] Copy or move .exe file when it runs

    Quote Originally Posted by RhinoBull View Post
    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.

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width