Index: /trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditions.nsi
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditions.nsi	(revision 40710)
+++ /trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditions.nsi	(revision 40711)
@@ -214,4 +214,5 @@
 Var g_bLogEnable                        ; Do logging when installing? "true" or "false"
 Var g_bWithWDDM                         ; Install the WDDM driver instead of the XPDM one
+Var g_bCapDllCache                      ; Capability: Does the (Windows) guest have have a DLL cache which needs to be taken care of?
 Var g_bCapWDDM                          ; Capability: Is the guest able to handle/use our WDDM driver?
 
@@ -793,40 +794,30 @@
   ; Update DLL cache
   ;
-  ${If} ${FileExists} "$g_strSystemDir\dllcache"
-    SetOutPath "$g_strSystemDir\dllcache"
-    ${IfNot} ${FileExists} "$g_strSystemDir\dllcache\msd3d8.dll"
-      CopyFiles /SILENT "$g_strSystemDir\dllcache\d3d8.dll" "$g_strSystemDir\dllcache\msd3d8.dll"
+  ${If} $g_bCapDllCache == "true"
+    ${If} ${FileExists} "$g_strSystemDir\dllcache"
+      SetOutPath "$g_strSystemDir\dllcache"
+      ${CopyFileEx} "" "$g_strSystemDir\dllcache\d3d8.dll" "$g_strSystemDir\dllcache\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+      ${CopyFileEx} "" "$g_strSystemDir\dllcache\d3d9.dll" "$g_strSystemDir\dllcache\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+
+      Push "$g_strSystemDir\dllcache\d3d8.dll"
+      Call PrepareWRPFile
+
+      Push "$g_strSystemDir\dllcache\d3d9.dll"
+      Call PrepareWRPFile
+
+      ; Exchange DLLs
+      ${InstallFileEx} "" "$%PATH_OUT%\bin\additions\d3d8.dll" "$g_strSystemDir\dllcache\d3d8.dll" "$TEMP"
+      ${InstallFileEx} "" "$%PATH_OUT%\bin\additions\d3d9.dll" "$g_strSystemDir\dllcache\d3d9.dll" "$TEMP"
+    ${Else}
+        DetailPrint "DLL cache does not exist, skipping"
     ${EndIf}
-    ${IfNot} ${FileExists} "$g_strSystemDir\dllcache\msd3d9.dll"
-      CopyFiles /SILENT "$g_strSystemDir\dllcache\d3d9.dll" "$g_strSystemDir\dllcache\msd3d9.dll"
-    ${EndIf}
-
-    Push "$g_strSystemDir\dllcache\d3d8.dll"
-    Call PrepareWRPFile
-
-    Push "$g_strSystemDir\dllcache\d3d9.dll"
-    Call PrepareWRPFile
-
-    ; Exchange DLLs
-    !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d8.dll" "$g_strSystemDir\dllcache\d3d8.dll" "$TEMP"
-    !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d9.dll" "$g_strSystemDir\dllcache\d3d9.dll" "$TEMP"
-
-    ; If exchange above failed, do it on reboot
-    !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d8.dll" "$g_strSystemDir\dllcache\d3d8.dll" "$TEMP"
-    !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d9.dll" "$g_strSystemDir\dllcache\d3d9.dll" "$TEMP"
-  ${Else}
-      DetailPrint "DLL cache does not exist, skipping"
-  ${EndIf}
-
+  ${EndIf}
+    
   ;
   ; Save original DLLs (only if msd3d*.dll does not exist) ...
   ;
   SetOutPath $g_strSystemDir
-  ${IfNot} ${FileExists} "$g_strSystemDir\msd3d8.dll"
-    CopyFiles /SILENT "$g_strSystemDir\d3d8.dll" "$g_strSystemDir\msd3d8.dll"
-  ${EndIf}
-  ${IfNot} ${FileExists} "$g_strSystemDir\msd3d9.dll"
-    CopyFiles /SILENT "$g_strSystemDir\d3d9.dll" "$g_strSystemDir\msd3d9.dll"
-  ${EndIf}
+  ${CopyFileEx} "" "$g_strSystemDir\d3d8.dll" "$g_strSystemDir\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+  ${CopyFileEx} "" "$g_strSystemDir\d3d9.dll" "$g_strSystemDir\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
 
   Push "$g_strSystemDir\d3d8.dll"
@@ -837,10 +828,6 @@
 
   ; Exchange DLLs
-  !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d8.dll" "$g_strSystemDir\d3d8.dll" "$TEMP"
-  !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d9.dll" "$g_strSystemDir\d3d9.dll" "$TEMP"
-
-  ; If exchange above failed, do it on reboot
-  !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d8.dll" "$g_strSystemDir\d3d8.dll" "$TEMP"
-  !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%PATH_OUT%\bin\additions\d3d9.dll" "$g_strSystemDir\d3d9.dll" "$TEMP"
+  ${InstallFileEx} "" "$%PATH_OUT%\bin\additions\d3d8.dll" "$g_strSystemDir\d3d8.dll" "$TEMP"
+  ${InstallFileEx} "" "$%PATH_OUT%\bin\additions\d3d9.dll" "$g_strSystemDir\d3d9.dll" "$TEMP"
 
 !if $%BUILD_TARGET_ARCH% == "amd64"
@@ -848,5 +835,5 @@
     ; Also copy 32-bit DLLs on 64-bit Windows in SysWOW64 node
     SetOutPath $g_strSysWow64
-    DetailPrint "Installing Direct3D support (SysWOW64: $g_strSysWow64) ..."
+    DetailPrint "Installing Direct3D support for 32-bit applications (SysWOW64: $g_strSysWow64) ..."
     FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\libWine.dll"
     FILE "$%VBOX_PATH_ADDITIONS_WIN_X86%\VBoxD3D8.dll"
@@ -857,28 +844,22 @@
     ; Update DLL cache
     ;
-    ${If} ${FileExists} "$g_strSysWow64\dllcache"
-      SetOutPath "$g_strSysWow64\dllcache"
-      ${IfNot} ${FileExists} "$g_strSysWow64\dllcache\msd3d8.dll"
-        CopyFiles /SILENT "$g_strSysWow64\dllcache\d3d8.dll" "$g_strSysWow64\dllcache\msd3d8.dll"
+    ${If} $g_bCapDllCache == "true"
+      ${If} ${FileExists} "$g_strSysWow64\dllcache"
+        SetOutPath "$g_strSysWow64\dllcache"
+        ${CopyFileEx} "" "$g_strSysWow64\dllcache\d3d8.dll" "$g_strSysWow64\dllcache\msd3d8.dll" "Microsoft Corporation" "x86"
+        ${CopyFileEx} "" "$g_strSysWow64\dllcache\d3d9.dll" "$g_strSysWow64\dllcache\msd3d9.dll" "Microsoft Corporation" "x86"
+
+        Push "$g_strSysWow64\dllcache\d3d8.dll"
+        Call PrepareWRPFile
+
+        Push "$g_strSysWow64\dllcache\d3d9.dll"
+        Call PrepareWRPFile
+
+        ; Exchange DLLs
+        ${InstallFileEx} "" "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll" "$g_strSysWow64\dllcache\d3d8.dll" "$TEMP"
+        ${InstallFileEx} "" "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll" "$g_strSysWow64\dllcache\d3d9.dll" "$TEMP"
+      ${Else}
+        DetailPrint "DLL cache does not exist, skipping"
       ${EndIf}
-      ${IfNot} ${FileExists} "$g_strSysWow64\dllcache\msd3d9.dll"
-        CopyFiles /SILENT "$g_strSysWow64\dllcache\d3d9.dll" "$g_strSysWow64\dllcache\msd3d9.dll"
-      ${EndIf}
-
-      Push "$g_strSysWow64\dllcache\d3d8.dll"
-      Call PrepareWRPFile
-
-      Push "$g_strSysWow64\dllcache\d3d9.dll"
-      Call PrepareWRPFile
-
-      ; Exchange DLLs
-      !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll" "$g_strSysWow64\dllcache\d3d8.dll" "$TEMP"
-      !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll" "$g_strSysWow64\dllcache\d3d9.dll" "$TEMP"
-
-      ; If exchange above failed, do it on reboot
-      !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll" "$g_strSysWow64\dllcache\d3d8.dll" "$TEMP"
-      !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll" "$g_strSysWow64\dllcache\d3d9.dll" "$TEMP"
-    ${Else}
-      DetailPrint "DLL cache does not exist, skipping"
     ${EndIf}
 
@@ -888,10 +869,6 @@
 
     ; Save original DLLs (only if msd3d*.dll does not exist) ...
-    ${IfNot} ${FileExists} "$g_strSysWow64\msd3d8.dll"
-      CopyFiles /SILENT "$g_strSysWow64\d3d8.dll" "$g_strSysWow64\msd3d8.dll"
-    ${EndIf}
-    ${IfNot} ${FileExists} "$g_strSysWow64\msd3d9.dll"
-      CopyFiles /SILENT "$g_strSysWow64\d3d9.dll" "$g_strSysWow64\msd3d9.dll"
-    ${EndIf}
+    ${CopyFileEx} "" "$g_strSysWow64\d3d8.dll" "$g_strSysWow64\msd3d8.dll" "Microsoft Corporation" "x86"
+    ${CopyFileEx} "" "$g_strSysWow64\d3d9.dll" "$g_strSysWow64\msd3d9.dll" "Microsoft Corporation" "x86"
 
     Push "$g_strSysWow64\d3d8.dll"
@@ -902,10 +879,6 @@
 
     ; Exchange DLLs
-    !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll" "$g_strSysWow64\d3d8.dll" "$TEMP"
-    !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll" "$g_strSysWow64\d3d9.dll" "$TEMP"
-
-    ; If exchange above failed, do it on reboot
-    !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll" "$g_strSysWow64\d3d8.dll" "$TEMP"
-    !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll" "$g_strSysWow64\d3d9.dll" "$TEMP"
+    ${InstallFileEx} "" "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d8.dll" "$g_strSysWow64\d3d8.dll" "$TEMP"
+    ${InstallFileEx} "" "$%VBOX_PATH_ADDITIONS_WIN_X86%\d3d9.dll" "$g_strSysWow64\d3d9.dll" "$TEMP"
 
 !endif ; amd64
@@ -1111,4 +1084,5 @@
   StrCpy $g_bOnlyExtract "false"
   StrCpy $g_bWithWDDM "false"
+  StrCpy $g_bCapDllCache "false"
   StrCpy $g_bCapWDDM "false"
   StrCpy $g_bPostInstallStatus "false"
Index: /trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditionsCommon.nsh
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditionsCommon.nsh	(revision 40710)
+++ /trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditionsCommon.nsh	(revision 40711)
@@ -565,4 +565,11 @@
   StrCpy $g_iSystemMode $0
 
+  ; Does the guest have a DLL cache?
+  ${If} $g_strWinVersion == "Vista"
+  ${OrIf} $g_strWinVersion == "7"
+  ${OrIf} $g_strWinVersion == "8"
+    StrCpy $g_bCapDllCache "true"
+  ${EndIf}
+
   ; Check whether this OS is capable of handling WDDM drivers
   Call ${un}CheckForWDDMCapability
@@ -760,7 +767,81 @@
   Push "${Vendor}"
   Push "${File}"
+  DetailPrint "Verifying file $\"${File}$\" ..."
   Call ${un}VerifyFile
 !macroend
 !define VerifyFileEx "!insertmacro VerifyFileEx"
+
+;
+; Macro for copying a file only if the source file is verified 
+; to be from a certain vendor and architecture.
+; @return  Stack: "0" if copied, "1" if not, "2" on error / not found.
+; @param   Un/Installer prefix; either "" or "un".
+; @param   Name of file to verify and copy to destination.
+; @param   Destination name to copy verified file to.
+; @param   Vendor to check for.
+; @param   Architecture ("x86" or "amd64") to check for.
+;
+!macro CopyFileEx un FileSrc FileDest Vendor Architecture
+  Push $0
+  Push "${Architecture}"
+  Push "${Vendor}"
+  Push "${FileSrc}"  
+  Call ${un}VerifyFile
+  Pop $0
+  ${If} $0 == "0"
+    DetailPrint "Copying verified file $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
+    CopyFiles /SILENT "${FileSrc}" "${FileDest}"
+  ${Else}
+    DetailPrint "Skipping to copy file $\"${FileSrc}$\" to $\"${FileDest}$\" (not Vendor: ${Vendor}, Architecture: ${Architecture})"
+  ${EndIf}
+  ; Push result popped off the stack to stack again.
+  Push $0
+!macroend
+!define CopyFileEx "!insertmacro CopyFileEx"
+
+;
+; Macro for installing a library/DLL.
+; @return  Stack: "0" if copied, "1" if not, "2" on error / not found.
+; @param   Un/Installer prefix; either "" or "un".
+; @param   Name of lib/DLL to verify and copy to destination.
+; @param   Destination name to copy verified file to.
+; @param   Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
+;
+!macro InstallFileEx un FileSrc FileDest DirTemp
+  DetailPrint "Installing library $\"${FileSrc}$\" to $\"${FileDest}$\" ..."
+  ; Try the gentle way and replace the file instantly
+  !insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
+  ; If the above call didn't help, use a (later) reboot to replace the file
+  !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED "${FileSrc}" "${FileDest}" "${DirTemp}"
+!macroend
+!define InstallFileEx "!insertmacro InstallFileEx"
+
+;
+; Macro for installing a library/DLL.
+; @return  Stack: "0" if copied, "1" if not, "2" on error / not found.
+; @param   Un/Installer prefix; either "" or "un".
+; @param   Name of lib/DLL to verify and copy to destination.
+; @param   Destination name to copy verified file to.
+; @param   Temporary folder used for exchanging the (locked) lib/DLL after a reboot.
+; @param   Vendor to check for.
+; @param   Architecture ("x86" or "amd64") to check for.
+;
+!macro InstallFileVerify un FileSrc FileDest DirTemp Vendor Architecture
+  Push $0
+  Push "${Architecture}"
+  Push "${Vendor}"
+  Push "${FileSrc}"
+  DetailPrint "Verifying library $\"${FileSrc}$\" ..."
+  Call ${un}VerifyFile
+  Pop $0
+  ${If} $0 == "0"
+    ${InstallFileEx} ${un} ${FileSrc} ${FileDest} ${DirTemp}
+  ${Else}
+    DetailPrint "File $\"${FileSrc}$\" did not pass verification (Vendor: ${Vendor}, Architecture: ${Architecture})"
+  ${EndIf}
+  ; Push result popped off the stack to stack again.
+  Push $0
+!macroend
+!define InstallFileVerify "!insertmacro InstallFileVerify"
 
 ;
@@ -793,10 +874,25 @@
   ${EndIf}
 
-  ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+  ${If} $g_bCapDllCache == "true"
+    ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+    Pop $0
+    ${If} $0 == "1"
+      Goto verify_msd3d
+    ${EndIf}
+    ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+    Pop $0
+    ${If} $0 == "1"
+      Goto verify_msd3d
+    ${EndIf}
+  ${EndIf}
+
+!if $%BUILD_TARGET_ARCH% == "amd64"
+
+  ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d8.dll" "Microsoft Corporation" "x86"
   Pop $0
   ${If} $0 == "1"
     Goto verify_msd3d
   ${EndIf}
-  ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\d3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+  ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d9.dll" "Microsoft Corporation" "x86"
   Pop $0
   ${If} $0 == "1"
@@ -804,26 +900,15 @@
   ${EndIf}
 
-!if $%BUILD_TARGET_ARCH% == "amd64"
-
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d8.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto verify_msd3d
-  ${EndIf}
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\d3d9.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto verify_msd3d
-  ${EndIf}
-
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d8.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto verify_msd3d
-  ${EndIf}
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d9.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto verify_msd3d
+  ${If} $g_bCapDllCache == "true"
+    ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d8.dll" "Microsoft Corporation" "x86"
+    Pop $0
+    ${If} $0 == "1"
+      Goto verify_msd3d
+    ${EndIf}
+    ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\d3d9.dll" "Microsoft Corporation" "x86"
+    Pop $0
+    ${If} $0 == "1"
+      Goto verify_msd3d
+    ${EndIf}
   ${EndIf}
 
@@ -845,10 +930,25 @@
   ${EndIf}
 
-  ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+  ${If} $g_bCapDllCache == "true"
+    ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d8.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+    Pop $0
+    ${If} $0 == "1"
+      Goto invalid
+    ${EndIf}
+    ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+    Pop $0
+    ${If} $0 == "1"
+      Goto invalid
+    ${EndIf}
+  ${EndIf}
+
+!if $%BUILD_TARGET_ARCH% == "amd64"
+
+  ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d8.dll" "Microsoft Corporation" "x86"
   Pop $0
   ${If} $0 == "1"
     Goto invalid
   ${EndIf}
-  ${VerifyFileEx} "${un}" "$SYSDIR\dllcache\msd3d9.dll" "Microsoft Corporation" "$%BUILD_TARGET_ARCH%"
+  ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d9.dll" "Microsoft Corporation" "x86"
   Pop $0
   ${If} $0 == "1"
@@ -856,26 +956,15 @@
   ${EndIf}
 
-!if $%BUILD_TARGET_ARCH% == "amd64"
-
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d8.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto invalid
-  ${EndIf}
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\msd3d9.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto invalid
-  ${EndIf}
-
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d8.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto invalid
-  ${EndIf}
-  ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d9.dll" "Microsoft Corporation" "x86"
-  Pop $0
-  ${If} $0 == "1"
-    Goto invalid
+  ${If} $g_bCapDllCache == "true"
+    ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d8.dll" "Microsoft Corporation" "x86"
+    Pop $0
+    ${If} $0 == "1"
+      Goto invalid
+    ${EndIf}
+    ${VerifyFileEx} "${un}" "$g_strSysWow64\dllcache\msd3d9.dll" "Microsoft Corporation" "x86"
+    Pop $0
+    ${If} $0 == "1"
+      Goto invalid
+    ${EndIf}
   ${EndIf}
 
