Results 1 to 19 of 19

Thread: How do I have my VB app copy its self?[sloved! yay! thanks all!]

  1. #1

    Thread Starter
    Banned
    Join Date
    Nov 2004
    Posts
    45

    Resolved How do I have my VB app copy its self?[sloved! yay! thanks all!]

    How do I have my VB app copy its self?
    Thanks.
    Last edited by the_inferno; Jan 6th, 2005 at 10:29 PM. Reason: Sloved

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I have my VB app copy its self?

    you can use SHELL "copy c:\sample\a.exe c:\backup" to copy the .exe

  3. #3

    Thread Starter
    Banned
    Join Date
    Nov 2004
    Posts
    45

    Re: How do I have my VB app copy its self?

    Quote Originally Posted by dglienna
    you can use SHELL "copy c:\sample\a.exe c:\backup" to copy the .exe
    Thanks but would'nt it have to be
    Quote Originally Posted by dglienna
    you can use SHELL "copy c:\sample\a.exe c:\backup.exe" to copy the .exe
    EDIT: oh and I noticed from another topic that, thats from the command prompt can't I do this in visual basic code? Thanks.

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

    Re: How do I have my VB app copy its self?

    Just use an ordinary Filecopy() - VB's native function.

  5. #5

    Thread Starter
    Banned
    Join Date
    Nov 2004
    Posts
    45

    Re: How do I have my VB app copy its self?

    Thanks. Thats helpful but I still need to know one more thing, the app path, how do I do that?

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

    Re: How do I have my VB app copy its self?

    Isn't your exe located in your application's directory ??? Who else would know ???

    FileCopy App.Path & "\myexe.exe", "c:\temp\myexe.exe"

  7. #7
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: How do I have my VB app copy its self?

    App.Path function

    dim myProgramPath as string
    myProgramPath = App.Path

    to get the exact path + filename

    App.Path & "\myapp.exe"
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  8. #8
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: How do I have my VB app copy its self?

    You beat me Rhino

    *bows at your greatness*


    the_inferno, Maybe you should read up on commonly used VB Functions... your coding experience would be made alot easier when you know the syntax
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

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

    Re: How do I have my VB app copy its self?

    Quote Originally Posted by ice_531
    You beat me Rhino
    I'm not competing with nobody ...

  10. #10

    Thread Starter
    Banned
    Join Date
    Nov 2004
    Posts
    45

    Re: How do I have my VB app copy its self?

    Yay! thank you all very much you sloved my question, can this be done while the program is running?

  11. #11
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    Did you try it


    ::: Once your thread is resolved add [resolved] to your original post and a checkmark :::

    Oh and Happy New Year
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    you don't have to re-specify the filename, as long as it is a different path. filecopy works as well, but DOS in forever burnt into my brain

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    In MSDN I found for FileCopy :

    If you try to use the FileCopy statement on a currently open file, an error occurs.
    So I assume (I'm not sure) that you can't copy your own exe like that... Maybe with a batch file? However the CopyFileEx API works fine :

    VB Code:
    1. 'in a form (Form1)
    2. Private Sub Form_Load()
    3.     'KPD-Team 2001
    4.     'URL: [url]http://www.allapi.net/[/url]
    5.     'E-Mail: [email][email protected][/email]
    6.     Dim Ret As Long
    7.     'set the graphics mode to persistent
    8.     Me.AutoRedraw = True
    9.     'print some text
    10.     Me.Print "Click the form to abort the filecopy"
    11.     'show the form
    12.     Me.Show
    13.     'start copying
    14.     Ret = CopyFileEx(App.Path & "\YourExeNameHere.exe", "c:\copy.exe", AddressOf CopyProgressRoutine, ByVal 0&, bCancel, COPY_FILE_RESTARTABLE)
    15.     'show some text
    16.     Me.Print "Filecopy completed " + IIf(Ret = 0, "(ERROR/ABORTED)", "successfully")
    17. End Sub
    18. Private Sub Form_Click()
    19.     'cancel filecopy
    20.     bCancel = 1
    21. End Sub
    22.  
    23. 'in a module
    24. Public Const PROGRESS_CANCEL = 1
    25. Public Const PROGRESS_CONTINUE = 0
    26. Public Const PROGRESS_QUIET = 3
    27. Public Const PROGRESS_STOP = 2
    28. Public Const COPY_FILE_FAIL_IF_EXISTS = &H1
    29. Public Const COPY_FILE_RESTARTABLE = &H2
    30. Public Declare Function CopyFileEx Lib "kernel32.dll" Alias "CopyFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, ByRef pbCancel As Long, ByVal dwCopyFlags As Long) As Long
    31. Public bCancel As Long
    32. Public Function CopyProgressRoutine(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long, ByVal lpData As Long) As Long
    33.     'adjust the caption
    34.     Form1.Caption = CStr(Int((TotalBytesTransferred * 10000) / (TotalFileSize * 10000) * 100)) + "% complete..."
    35.     'allow user input
    36.     DoEvents
    37.     'continue filecopy
    38.     CopyProgressRoutine = PROGRESS_CONTINUE
    39. End Function


    Has someone helped you? Then you can Rate their helpful post.

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

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    Don't believe MSDN too much - you'll get burned, Manavo.
    What they say is true but doesn't really apply to executable files:
    VB Code:
    1. Private Sub Command1_Click()
    2.     FileCopy App.Path & "\" & App.EXEName & ".exe", _
    3.              "c:\temp\" & App.EXEName & ".exe"
    4. End Sub
    Compile and test it - that's all I can tell you.

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

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    Quote Originally Posted by dglienna
    you don't have to re-specify the filename, as long as it is a different path. filecopy works as well, but DOS in forever burnt into my brain
    It's about time to forget all about it ...

  16. #16
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    Quote Originally Posted by RhinoBull
    Don't believe MSDN too much - you'll get burned, Manavo.
    I guess you have a point there Trial & Error seems safer than MSDN


    Has someone helped you? Then you can Rate their helpful post.

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

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    Quote Originally Posted by manavo11
    ... Trial & Error seems safer than MSDN
    Indeed.

  18. #18

    Thread Starter
    Banned
    Join Date
    Nov 2004
    Posts
    45

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    Hey thanks.
    P.s ehy you ever notice that its like half that little feller arm comes off in that wave?



    Meet the fouckers comming to theaters.

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

    Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]

    You're welcome but this is not a chit-chat, inferno.

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