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. :wave:
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
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.
Re: How do I have my VB app copy its self?
Just use an ordinary Filecopy() - VB's native function.
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?
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"
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"
Re: How do I have my VB app copy its self?
You beat me Rhino :(
*bows at your greatness*
:afrog:
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 :ehh:
Re: How do I have my VB app copy its self?
Quote:
Originally Posted by ice_531
You beat me Rhino :(
:ehh:
I'm not competing with nobody ... ;)
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?
Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]
Did you try it :p
::: Once your thread is resolved add [resolved] to your original post and a checkmark ;) :::
Oh and Happy New Year :D
:wave:
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 ;)
Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]
In MSDN I found for FileCopy :
Quote:
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:
'in a form (Form1)
Private Sub Form_Load()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
Dim Ret As Long
'set the graphics mode to persistent
Me.AutoRedraw = True
'print some text
Me.Print "Click the form to abort the filecopy"
'show the form
Me.Show
'start copying
Ret = CopyFileEx(App.Path & "\YourExeNameHere.exe", "c:\copy.exe", AddressOf CopyProgressRoutine, ByVal 0&, bCancel, COPY_FILE_RESTARTABLE)
'show some text
Me.Print "Filecopy completed " + IIf(Ret = 0, "(ERROR/ABORTED)", "successfully")
End Sub
Private Sub Form_Click()
'cancel filecopy
bCancel = 1
End Sub
'in a module
Public Const PROGRESS_CANCEL = 1
Public Const PROGRESS_CONTINUE = 0
Public Const PROGRESS_QUIET = 3
Public Const PROGRESS_STOP = 2
Public Const COPY_FILE_FAIL_IF_EXISTS = &H1
Public Const COPY_FILE_RESTARTABLE = &H2
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
Public bCancel As Long
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
'adjust the caption
Form1.Caption = CStr(Int((TotalBytesTransferred * 10000) / (TotalFileSize * 10000) * 100)) + "% complete..."
'allow user input
DoEvents
'continue filecopy
CopyProgressRoutine = PROGRESS_CONTINUE
End Function
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. :p
What they say is true but doesn't really apply to executable files:
VB Code:
Private Sub Command1_Click()
FileCopy App.Path & "\" & App.EXEName & ".exe", _
"c:\temp\" & App.EXEName & ".exe"
End Sub
Compile and test it - that's all I can tell you. :wave:
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 ... ;) :p :D
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. :p
I guess you have a point there :) Trial & Error seems safer than MSDN :D
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 :D
Indeed. ;)
Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]
Hey thanks.
P.s :wave: ehy you ever notice that its like half that little feller arm comes off in that wave?
Meet the fouckers comming to theaters.
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.