windows在update打补丁时update程序总可以替换系统dll(如果dll正使用通过一次系统重启也能替换),那程序如何写才能做到这点??

解决方案 »

  1.   

    1.用MoveFileEx将dll改名
    2.将新的dll拷贝到原来dll的地方
    3.用MoveFileEx删除原来的dll文件详细步骤请参看msdn:
    1.Use the MoveFileEx function to rename the DLL being replaced. Do not specify MOVEFILE_COPY_ALLOWED, and make sure the renamed file is on the same volume that contains the original file. You could also simply rename the file in the same directory by giving it a different extension. 
    2.Copy the new DLL to the directory that contains the renamed DLL. All applications will now use the new DLL. 
    3.Use MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT to delete the renamed DLL. 
    Before you make this replacement, applications will use the original DLL until it is unloaded. After you make the replacement, applications will use the new DLL. When you write a DLL, you must be careful to ensure that it is prepared for this situation, especially if the DLL maintains global state information or communicates with other services. If the DLL is not prepared for a change in global state information or communication protocols, updating the DLL will require you to restart the computer to ensure that all applications are using the same version of the DLL.
    Windows Me/98/95:  Because MoveFileEx is not supported, it is necessary to restart the computer. For more information, see the Res section of MoveFileEx.
      

  2.   

    可是msdn里又有:Windows File Protection
    PurposeWindows® File Protection (WFP) prevents the replacement of essential system files installed as part of Windows. Applications should not overwrite these files because they are used by the system and other applications. Protecting these files prevents application and operating system failures.
    Where ApplicableAll Windows-based applications and their installation programs should be aware of WFP.
    Developer AudienceThe WFP API is designed for use by C/C++ programmers.
    Run-Time RequirementsApplications that use the WFP API require Microsoft® Windows® Server 2003 family, Windows XP, Windows 2000, or Windows Millennium Edition.Supported File Replacement MechanismsReplacement of protected system files is supported only through the following mechanisms:
    Windows Service Pack installation using Update.exe 
    Hotfixes installed using Hotfix.exe 
    Operating system upgrades using Winnt32.exe 
    Windows Update 
    Replacing protected files by means other than these specified methods results in the original files being restored by WFP.
      

  3.   

    因为是rpc的漏洞补丁更新,我担心dllcache会对更新有影响,所以是先把新的dll复制到dllcache,然后按照RickeyLau的说法做,成功了。
    不知道如果不先做dllcache的覆盖,按这个方法直接替换system32下的dll,重启后wfp会不会自动用dllcache里的dll对system32做恢复?