Jump to content
Sign in to follow this  
MPlb

Overwriting files

Recommended Posts

I am trying to overwrite a DLL file located in C:\Windows\System32 with a new version using AutoIt3 and am running into trouble if the DLL is in use by the system.

I'm using the FileCopy command with the 1 switch to overwrite existing files but it's not working when something else has a lock on the file.

Is there a way this can be done when the DLL is locked by some other process?

Thanks

Share this post


Link to post
Share on other sites

When a file is inuse and needs to be replaced, typically it's put into a special registry key that holds the names of the source file (new file) and the destination for the file (old file which is in use and needs to be replaced).

The registry key is "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager", the Value is "PendingFileRenameOperations", and is a a REG_MULTI_SZ type key.

Now normally I'd just say write a quick function to take care of this, but there's a problem with the way the key can be used.

Temporary files can be set as the destination file with the source being NULL. When that happens, you end up with double nulls 0 - in binary 00,00,00,00,00 - and RegWrite doesn't handle it properly.

I played with this a lot in an attempt to create a function similar to SysInternal's MoveFile utility (part of PendMoves), or like the Inuse tool from Microsoft, but have never been able to work out the issue.

Your best bet would be to use one of those utilities and then RUN it unless someone has a way to work out the RegWrite problem!

Share this post


Link to post
Share on other sites

Is this a one time thing or does this have to be applied to hundreds of machines?

What is the name of the file?

I would use something like ProcessExplorer to determine what process is locking that file, stop it temporarily, then overwrite.

Share this post


Link to post
Share on other sites

Temporary files can be set as the destination file with the source being NULL. When that happens, you end up with double nulls 0 - in binary 00,00,00,00,00 - and RegWrite doesn't handle it properly.

...

Your best bet would be to use one of those utilities and then RUN it unless someone has a way to work out the RegWrite problem!

@JerryD: I'm not sure what you mean about the source being NULL. In my experience, the source must always exist, and the destination could be a file name (replace) or it could be null (delete).

However, I have seen issues where the null values were somehow removed. (Regedit will do this if you try to edit the value)

Regedit doesn't handle Nulls in REG_MULTI_SZ values, but AutoIt does.

I have written a function in AutoIt that populates the PendingFileRenameOperations value, and it has been working on hundreds of machines. (hundreds of files/folders zapped per system)

Post the code you had issues with and we'll see if we can figure it out.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...