Quantcast
Channel: Detect if Visual C++ Redistributable for Visual Studio 2012 is installed - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by Michael for Detect if Visual C++ Redistributable for Visual Studio 2012 is installed

$
0
0

The answer to this simple questions is unfortunately not a simple one, but working in 100% of all systems, and even extendable to the numerous .net frameworks.

The complexity comes from the fact that there are (and were) many VC runtimes revisions which could lead to the case that although VC10 runtimes were installed, their build number was not recent enough so your EXE wouldn't start unless you either installed the very exact runtimes you required or one of the newer runtimes which enable this and previous versions for the same major version to run with it (the side-by-side hell).Also, if you have a 64 bit EXE, you will have to check for both, the 32 AND 64 bit runtimes.

That said, the only reliable way to determine whether the runtimes for your EXE are installed is to attempt to run the EXE - or a another EXE which is built with the same settings as your main EXE and whose only purpose is to do - nothing. Just run (which means the runtimes are installed) or fail to run (when not installed).

I did the following for an installer which required the VC10 32 and 64 bit runtimes installed: The installer attempts to launch all dummy EXEs and if it succeeds, the corresponding runtime is considered to be installed. This also resolves the 32/64 bit scenario.

This, by the way, works also to determine if the proper .net framework is installed, which is very tricky in Windows 8 and 10, as the downloadable built-in .net 3.5 support also supports the .net versions 3.0 and 2.0 - there are no registry entries for these.(And worse, you cannot even use the standard framework installers here, you must use the built-in support and download it via Windows, or rebuild your app with .net 4, but that's another story).

The C++ dummy EXE can be built using a project with the following code (and another one in a 64 bit configuration if necessary):

int _tmain(int argc, _TCHAR* argv[]){    return 0;}

Remember to set the project's properties Use of MFC to Use MFC in a shared DLL.The executables will be around 4KB in size - a small price to pay for a sure result.

To give your users a nice installation experience, you could do the following (sample code is for NSIS):

Function TryLaunchApplication  Pop $1 ; pathname  nsExec::Exec $1  Pop $0  ${If} $0 == "error"  ${OrIf} $0 != 0    Push 0  ${Else}    Push 1  ${EndIf}FunctionEnd

and call it in a function, e.g. CheckRuntimes

Function CheckRuntimes  ; Try to execute VC++ 10 application (32 bit)  Push "Vc10RuntimeCheckerApp.exe"  Call TryLaunchApplication  Pop $Vc10RuntimesFound  ; Add 64 bit check if required.  ; Remember to try running the 64 bit EXE only on a 64 bit OS,  ; which requires further checks.  ; Try to execute .net application  Push "DotNetRuntimeCheckerApp.exe"  Call TryLaunchApplication  Pop $DotNetFrameworkFoundFunctionEnd

Then launch the runtime check e.g. when leaving the Welcome page and cache the result, so you don't have to re-check every time the user clicks on the "Back" and "Next" button.

Next, make a read-only section in the install tree and pre-select or unselect it on the a function which is executed before the Components page is shown.

This will make sure that the installation of each missing runtime component is mandatory, and is skipped if it is already present.


Viewing all articles
Browse latest Browse all 22

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>