shadow copy question

  • Thread starter Thread starter Michael Dybevick
  • Start date Start date
M

Michael Dybevick

I'd like to be able to overwrite an .exe file while a process started from
it is running, like one can do with .dlls when started through an AppDomain
object.

Is there a way to start a process from and .exe so that the executable
source is shadow copied.
 
Hello Michael,

Thanks for your post. As I understand, you want to shadow copy the
executable file started by the main AppDomain. Please correct me if there
is any misunderstanding. Based on my experience, the executable file
started by main AppDomain remains locked during code execution and cannot
be shadow copyied. To work around the problem, I suggest that you can
create a stub app which in turns create a new AppDomain with setting
ShadowCopyFiles to true to start your executable file. Please refer to the
following code snippet:

'---------------------code snippet-------------------
Sub main()
' create a new evidence object,
' based on the current appdomain
Dim myDomainSetup = New System.AppDomainSetup()

myDomainSetup.ShadowCopyFiles = "true"

With AppDomain.CreateDomain( _
"sample", AppDomain.CurrentDomain.Evidence, _
myDomainSetup)
.ExecuteAssembly("MyExecutable.exe")
End With
End Sub
'---------------------------------end of------------------------------

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
That certainly works well enough.

The problem is that the code in the new executable is still running in the
same process as the stub program. For most cases this would be OK and maybe
even a good thing, but in the particular case I am working with (because of
the characteristics of a third party package) I need to spawn and control
completely separate processes. If I try to do more than one thing per
process, even though they are in separate AppDomains, I get problems.
 
Hi Michael,

Thanks for your reply. If the stub application is not a solution for you, I
suggest that you may be able to work around the problem by calling
MoveFileEx(). When you need to update an .exe file which is running, you
can save the newer file in another directory and then call MoveFileEx()
with the flags MOVEFILE_DELAY_UNTIL_REBOOT and MOVEFILE_REPLACE_EXISTING so
that the .exe file will be replaced after restarting your machine.

MoveFileEx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base
/movefileex.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top