|
-
Jan 6th, 2005, 09:58 PM
#1
Thread Starter
Banned
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
-
Jan 6th, 2005, 10:00 PM
#2
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
-
Jan 6th, 2005, 10:04 PM
#3
Thread Starter
Banned
Re: How do I have my VB app copy its self?
 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
 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.
-
Jan 6th, 2005, 10:08 PM
#4
Re: How do I have my VB app copy its self?
Just use an ordinary Filecopy() - VB's native function.
-
Jan 6th, 2005, 10:14 PM
#5
Thread Starter
Banned
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?
-
Jan 6th, 2005, 10:16 PM
#6
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"
-
Jan 6th, 2005, 10:16 PM
#7
Frenzied Member
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++
-
Jan 6th, 2005, 10:18 PM
#8
-
Jan 6th, 2005, 10:23 PM
#9
Re: How do I have my VB app copy its self?
 Originally Posted by ice_531
You beat me Rhino

I'm not competing with nobody ...
-
Jan 6th, 2005, 10:27 PM
#10
Thread Starter
Banned
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?
-
Jan 6th, 2005, 10:30 PM
#11
Frenzied Member
-
Jan 6th, 2005, 10:33 PM
#12
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
-
Jan 6th, 2005, 10:34 PM
#13
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:
'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
Has someone helped you? Then you can Rate their helpful post. 
-
Jan 6th, 2005, 10:43 PM
#14
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:
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.
-
Jan 6th, 2005, 10:45 PM
#15
Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]
-
Jan 6th, 2005, 10:58 PM
#16
-
Jan 6th, 2005, 11:07 PM
#17
Re: How do I have my VB app copy its self?[sloved! yay! thanks all!]
 Originally Posted by manavo11
... Trial & Error seems safer than MSDN 
Indeed.
-
Jan 6th, 2005, 11:30 PM
#18
Thread Starter
Banned
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.
-
Jan 6th, 2005, 11:54 PM
#19
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|