How to replace process file itself?

Y

yxq

Hello,
I want to update A program file from A.
First startup A, then startup B process from A, close A, B will copy new
file to replace A file.
But system states that A is using.

A code:
////////////////////////////////////////////
Dim objProcess As New Process
objProcess.StartInfo.FileName = "B.exe"
objProcess.Start()
Me.Close()

B code:
///////////////////////////////////////////
IO.File.Copy(NewFile, A.exe, True)



Thank you.
 
R

rowe_newsgroups

Hello,
I want to update A program file from A.
First startup A, then startup B process from A, close A, B will copy new
file to replace A file.
But system states that A is using.

A code:
////////////////////////////////////////////
Dim objProcess As New Process
objProcess.StartInfo.FileName = "B.exe"
objProcess.Start()
Me.Close()

B code:
///////////////////////////////////////////
IO.File.Copy(NewFile, A.exe, True)

Thank you.

How much time are you giving "A" to close before trying to run the
code in "B"?

Thanks,

Seth Rowe
 
P

Phill W.

yxq said:
I want to update A program file from A.
First startup A, then startup B process from A, close A, B will copy new
file to replace A file.
But system states that A is using.

A code:
////////////////////////////////////////////
Dim objProcess As New Process
objProcess.StartInfo.FileName = "B.exe"
objProcess.Start()
Me.Close()

B code:
///////////////////////////////////////////
IO.File.Copy(NewFile, A.exe, True)

It /may/ be that B is simply starting up too quickly for the process
running A to get out of the way.

Add a delay (of a few seconds) to the startup code in B and see if that
makes any difference:

Module B
Shared Function Main( ByVal args() as String ) As Integer
System.Threading.Thread.Sleep( 15000 )
System.IO.File.Copy( "A+.exe", "A.exe", True )
Return 0

HTH,
Phill W.
 
Y

yxq

I have sloved this problem, add the code into B.

//////////////////////////////////////////////////////////////////
Try
Dim p As Process() = Process.GetProcessesByName("A")
Do Until p(0).HasExited
Application.DoEvents()
Loop
Catch ex As Exception
End Try

IO.File.Copy(NewFile, A.exe, True)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top