Hey all! I am trying to write a piece of code that will replace one of my system files on reboot with a new version of that file. Hopefully someone out there has some experience with this as I am stumped at the moment.

Using: VB.NET 2012

Using MoveFileEx

    Public Declare Function MoveFileEx Lib "kernel32" Alias "MoveFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal dwFlags As Integer) As Integer

Code in Form

MoveFileEx("C:\windows\system32\file.name", My.Application.Info.DirectoryPath + "\file.name", 4)

Resource for this API call at MSDS: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx

Im using flag code 4, which is MOVEFILE_DELAY_UNTIL_REBOOT. I have also tried flag code 5 which is MOVEFILE_DELAY_UNTIL_REBOOT and MOVEFILE_REPLACE_EXISTING to no success.

If anyone can shed some light on this, the help would be very much appreciated.

Thank you in advance :)

If anyone is familiar with Se7en File Replacer, pretty much the same thing im trying to do.

Ok, not getting any responses and I think it may be due to the complexity of preserving permissions and policies for system files.. dont worry, I have that covered. There was actually a pretty good tutorial on this in the sample section of Visual Studio that connects to MSDN. I just can't figure out why MoveFileEx isn't doing what its suppose to do. I will double check and see if it works on a non-system directory tonight.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.