Replacing Windows System Files Live
Recently I had the need to replace Windows system files manually, while Windows is running. For those of you have tried this in the past you may know that it is easier said than done. Windows protects these files and/or they may be in use and then the error you get is “Access Denied”.
After searching high and low for a solution I stumbled across a StackOverflow page that provided the solution – http://stackoverflow.com/questions/4443578/how-to-replace-locked-dll-was-inuse
Copying system dlls on Windows 7 (and Vista) is described in System File Checker tool article (in “Step2: If the System File Checker tool cannot repair a file”).
Here is a quick (almost copy&paste) solution to use in a batchfile:
REM you will need to change this :-) - the SOURCE and the DESTINATION SET tmpset_SOURCE=c:\Temp\fileyouwanttoreplace.dll SET tmpset_DEST=c:\Windows\SysWOW64\fileyouwanttoreplace.dll REM copy and paste this straight to cmd: takeown /f %tmpset_DEST% icacls %tmpset_DEST% /GRANT %USERNAME%:F copy %tmpset_SOURCE% %tmpset_DEST%
For those of you who want to understand what is happening above, lets break it down.
- Firstly the Source and the Destination variables are being set
- The “takeown” command is taking ownership of the destination file by force
- The “icacls” command is setting the permission of the destination file to the currently logged on user
- The copy command
It worked like a charm and this is something you want to keep in your “Admins Toolkit” 🙂