Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Verifying Visual C++ Redistributable Files in Custom .NET Applications

DZone's Guide to

Verifying Visual C++ Redistributable Files in Custom .NET Applications

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

This article was written by the Imaginovation team.  They are a Raleigh web design and software development company who uses .NET, PHP, HTML5, JavaScript, and jQuery technologies.

As you may already know the MS VC++ Redistributable run time files allow you to execute programs which were developed with specific versions of Visual Studio.  The need might arise to check a client system for these files in the scenario where you are deploying you’re application and want to deploy the VCR’s iff the user’s system does not have these installed, saving time and overhead.

First let’s get past the very difficult and confusing naming convention:
VCR7(which we will not discuss how to detect in this article) corresponds to Visual Studio 2003

VCR8 corresponds to Visual Studio 2005

VCR9 corresponds to Visual Studio 2008

VCR10 corresponds to Visual Studio 2010

 
Next we will detect the presence of these VCR’s and add it to a list of strings using the following code snippet:
The enumerated type is first defined:
public enum INSTALLSTATE

        {

           INSTALLSTATE_NOTUSED = -7,  // component disabled

           INSTALLSTATE_BADCONFIG = -6,  // configuration data corrupt

           INSTALLSTATE_INCOMPLETE = -5,  // installation suspended or in progress

           INSTALLSTATE_SOURCEABSENT = -4,  // run from source, source is unavailable

           INSTALLSTATE_MOREDATA = -3,  // return buffer overflow

           INSTALLSTATE_INVALIDARG = -2,  // invalid function argument

           INSTALLSTATE_UNKNOWN = -1,  // unrecognized product or feature

           INSTALLSTATE_BROKEN = 0,  // broken

           INSTALLSTATE_ADVERTISED = 1,  // advertised feature

           INSTALLSTATE_REMOVED = 1,  // component being removed(action state, not settable)

           INSTALLSTATE_ABSENT = 2,  // uninstalled (or action state absent but clients remain)

           INSTALLSTATE_LOCAL = 3,  // installed on local drive

           INSTALLSTATE_SOURCE = 4,  // run from source, CD or net

           INSTALLSTATE_DEFAULT = 5,  // use default, local or source

        }
/*Use this function to determine which bit type of the VCR is installed.  The below logic is basically saying if you can open the key then it exists (you can pass in only certain states depending on your needs.  The most commonly “good states” I use are Local and Default, you might need to pass in all states for debugging purposes.
*/
        private void CheckVCKey(string _vcKey, string _state)

        {

            string value64 = string.Empty;

            string value32 = string.Empty;

 

            if (Environment.Is64BitOperatingSystem == true)

            {

 

                RegistryKey localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);

                localKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + _vcKey);

 

                if (localKey != null)

                {

                    value64 = localKey.GetValue("DisplayName").ToString() + " at Registry Key " + _vcKey + " with a state of " + _state;

                    VCresults.Add(value64);

                }

            }

           

            RegistryKey localKey32 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);

 

            localKey32 = localKey32.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + _vcKey);

            if (localKey32 != null)

            {

                value32 = localKey32.GetValue("DisplayName").ToString() + " at Registry Key " + _vcKey + " with a state of " + _state; ;

                VCresults.Add(value32);

            }

 
public bool IsVCRedistInstalled()

{           
       string[,] strCodes = new string[,]  (this is the most important (and annoying) part of this document, and this string list will be defined below the code snippet)
INSTALLSTATE state;

 

for (int i = 0;i < strCodes.Length; i++){

                //you can modify this as needed with any of the enumerated types

if (state == INSTALLSTATE.INSTALLSTATE_LOCAL||

                     state == INSTALLSTATE.INSTALLSTATE_DEFAULT)

                {

                   CheckVCKey(strCodes[i], state.ToString());

       }

}

Now we will list the codes (please be aware this is an ever changing list and I will try to keep it updated as much as I can)  :

string[,] strCodes = new string[,]
           {

 

                //VC8

                //vcredist_x86 - ProductCode

                {"{710f4c1c-cc18-4c49-8cbf-51240c89a1a2}"},   //8.0.61001  - distributed in 152

                {"{A49F249F-0C91-497F-86DF-B2585E8E76B7}"},

                {"{7299052B-02A4-4627-81F2-1818DA5D550D}"},

                {"{837B34E3-7C30-493C-8F6A-2B0F04E2912C}"},

 

                //vcredist_x64 - ProductCode

                {"{6E8E85E8-CE4B-4FF5-91F7-04999C9FAE6A}"},

                {"{071C9B48-7C32-4621-A0AC-3F809523288F}"},

                {"{6CE5BAE9-D3CA-4B99-891A-1DC6C118A5FC}"},

                {"{AD8A2FA1-06E7-4B0D-927D-6E54B3D31028}"},

 

                //vcredist_IA64 - ProductCode

                {"{C2F60BDA-462A-4A72-8E4D-CA431A56E9EA}"},

                {"{03ED71EA-F531-4927-AABD-1C31BCE8E187}"},

                {"{0F8FB34E-675E-42ED-850B-29D98C2ECE08}"},

                {"{85025851-A784-46D8-950D-05CB3CA43A13}"},

               

                //VC9

                //vcredist_x86 - ProductCode

                {"{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}"},

                {"{1F1C2DFC-2D24-3E06-BCB8-725134ADF989}"},

                {"{9BE518E6-ECC6-35A9-88E4-87755C07200F}"},

                {"{9A25302D-30C0-39D9-BD6F-21E6EC160475}"},

                {"{86CE1746-9EFF-3C9C-8755-81EA8903AC34}"},

                {"{CA8A885F-E95B-3FC6-BB91-F4D9377C7686}"},

                {"{820B6609-4C97-3A2B-B644-573B06A0F0CC}"},

                {"{6AFCA4E1-9B78-3640-8F72-A7BF33448200}"},

                {"{F03CB3EF-DC16-35CE-B3C1-C68EA09E5E97}"},

                {"{402ED4A1-8F5B-387A-8688-997ABF58B8F2}"},

                {"{887868A2-D6DE-3255-AA92-AA0B5A59B874}"},

                {"{527BBE2F-1FED-3D8B-91CB-4DB0F838E69E}"},

                {"{57660847-B1F7-35BD-9118-F62EB863A598}"},

 

                //vcredist_x64 - ProductCode

                {"{350AA351-21FA-3270-8B7A-835434E766AD}"},

                {"{4B6C7001-C7D6-3710-913E-5BC23FCE91E6}"},

                {"{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}"},

                {"{8220EEFE-38CD-377E-8595-13398D740ACE}"},

                {"{56F27690-F6EA-3356-980A-02BA379506EE}"},

                {"{14297226-E0A0-3781-8911-E9D529552663}"},

                {"{9B3F0A88-790D-3AD9-9F96-B19CF2746452}"},

                {"{D285FC5F-3021-32E9-9C59-24CA325BDC5C}"},

                {"{092EE08C-60DE-3FE6-B113-90076EC06D0D}"},

                {"{A96702F7-EFC8-3EED-BE46-22C809D4EBE5}"},

                {"{92B8FD1F-C1AE-3750-8577-631B0AA85DF5}"},

                {"{2DFD8316-9EF1-3210-908C-4CB61961C1AC}"},

                {"{E34002C7-8CE7-3F76-B36C-09FA973BC4F6}"},

 

                //vcredist_IA64 - ProductCode

                {"{2B547B43-DB50-3139-9EBE-37D419E0F5FA}"},

                {"{977AD349-C2A8-39DD-9273-285C08987C7B}"},

                {"{515643D1-4E9E-342F-A75A-D1F16448DC04}"},

                {"{5827ECE1-AEB0-328E-B813-6FC68622C1F9}"},

                {"{9363B366-8370-34F7-8164-25052EBF35FD}"},

                {"{4EC84186-70BB-3121-9C1B-C63512D7126E}"},

                {"{1F7B9797-A3C8-3B98-85C4-00620F221CE8}"},

                {"{6BE0A7C7-3462-30EE-8B77-D21D7848D967}"},

                {"{BF58DC07-38AB-3887-8000-70173F9650EA}"},

                {"{D289009A-2728-3D0A-833E-F08E0E58934C}"},

                {"{9476DC14-00C3-3C36-A435-00D714CF77B8}"},

                {"{678835D7-D524-3C0E-9C33-1D3767FDA6BF}"},

 

                //vc10_x86 - ProductCode

                {"{196BB40D-1578-3D01-B289-BEFC77A11A1E}"},

 {"{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}"},

               

                 //vc10_x64 - ProductCode

               {"{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}"},

                {"{1D8E6291-B0D5-35EC-8441-6616F567A0F7}"},

               

 

 



//vc10_x86 - ProductCode

                {"{94D70749-4281-39AC-AD90-B56A0E0A402E}"},

 {"{88C73C1C-2DE5-3B01-AFB8-B46EF4AB41CD}"},

{"{C1A35166-4301-38E9-BA67-02823AD72A1B}"},

               

 

            };

 
I hope this article helps those in need of detecting VCR’s and you had as much fun reading it as I did writing it!

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Michael Georgiou. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}