Click here to Skip to main content
12,691,789 members (29,572 online)
Click here to Skip to main content
Add your own
alternative version


45 bookmarked

Is .NET Framework installed on this machine???

, 26 Apr 2007
Rate this:
Please Sign up or sign in to vote.
Find out if .NET Framework is installed on the machine, before running your .NET code-based program.
Screenshot - dotNetTester.gif


Have you ever had a client who claims that your application is constantly failing on one of his machines, only to later find he has no .NET Framework installed there? How do you test if the (right version of the) Framework exists if all your code is .NET based? This is the sort of chicken-and-egg question that requires thinking outside the box...


I manage the Professional Services team for my company. We're in charge of installation, integration and customization of our products. Every once in a while, we would have to write a small utility, wrapper, or sample code for a client. We usually use Visual Studio (2003 or 2005 - based on the client's environment) and create a .NET utility quite easily. Once the tool becomes widely used, we wrap it up in a nice MSI (created in Visual Studio as a Setup Project - no time/money for InstallShield).

An installer-deployed tool can rely on its installer to check for the existence and even provide an installation of the .NET Framework. But the greatest annoyance for us are clients who don't have the Framework installed at all, or have it on some machines. If they use our standalone (installer-less) tools, there's no way to test that the right Framework is installed. When a .NET application is run on a Framework-less machine, the results are unpredictable: the application will either not work, crash, or be frozen as an open window that does nothing...

At first, someone suggested a short VB 6 app - but that was ruled out - who's to say that our client would have VB runtime installed? This called for plain-old Win32, console application (and let's admit it, I wanted to flex those unused muscles myself).

After starting at the usual place for Microsoft related hassles (Google Microsoft Search), I got to this support article. It contains a long piece of code that checks some registry keys. The catch - it's compiled in C++ .NET. Search a little more, and you find this article, by Junfeng Zhang, which explains that you need to look at a single registry key to get the info you need:

Registry key and subkeys we're looking for

And so, I wrote a short piece of C++ code in Visual Studio 6.0, called dotNetTester, that does 3 simple things:

  1. Checks whether that key exists.
  2. Checks for the latest Framework version subkey underneath that key and compares it to the required FW version.
  3. Upon success of the first 2, launches an application (the real .NET application).

Using the application

Compile the code in Visual Studio 6.0, or just use the compiled version (unoptimized, release) like this:

dotNetTester.exe <FW version formatted major.minor> 
                [<path of app to run>]

For example (test for a minimum of FW 1.1 and launch an application):

dotNetTester.exe 1.1 C:\Temp\Myapp.exe

Or (test for the existence of FW 2.0, and do nothing, just report):

dotNetTester.exe 2.0

Now, of course, comes the packaging: we use a self-extracting, self-executing ZIP file (created with WinZip or WinRar), to launch dotNetTester, and through it, the real app.

Luckily, they'll both be automatically extracted into the same folder, so getting the path is a non-issue.

The code

Here's the code of the main() function::

// Main function
int main(int argc, char* argv[])
    TCHAR fwVersion[VERSION];

    // Ensure correct number of parameters
    if(argc < 2 || argc > 3)
        printf("Usage: dotNetTester <minimum FW version (x.y)>
                                [<path of app to run>]\n");

    // Check if Framework key exists and get the FW version if yes
        // Compare versions
        if(CompareFWVersions(fwVersion, argv[1]))
            // Launch an application, if the user requested it
            if(3 == argc)
            // Minimum FW requirement not met
            printf("Minimum required .NET Framework version is %s,
                you have version %s installed. Please install the 
                proper .NET Framework\n", argv[1], fwVersion);
        // No FW exists
        printf("Please install the latest .NET Framework  -
            it can be downloaded from Microsoft\n", argv[1], fwVersion);

    return 0;

And here's the version comparison "algorithm":

//Compare the existing and required FW version numbers
bool CompareFWVersions(TCHAR *existing, TCHAR *required)
    int existingMajor = atoi(existing);
    int existingMinor = atoi(existing+2);
    int requiredMajor = atoi(required);
    int requiredMinor = atoi(required+2);
    bool result = false;

    // very simple comparison algorithm, really
    if(requiredMajor < existingMajor)
        result = true;
    else if(requiredMajor == existingMajor && requiredMinor <= existingMinor)
        result = true;
        result = false;
    return result;

The application will be launched using WinExec - the shortest and easiest function I found.

Points of Interest

This is a QAD (Quick and Dirty) development, done in one seating, with plenty of music and teeth-rotting soda.

There's plenty to fix here:

  • Use proper string manipulation functions.
  • There's probably an easier way to read from the registry
  • The WinExec function is probably obsolete, but it still works.
  • Add support (and test) complex application paths...

In the future, I'd like to explore better ways of repackaging this tiny application.

One last point of interest: Windows Vista comes with FW 2.0 pre-installed, so my application is not needed there. Same for Windows 2003 R2.


  • Version 1.0 - if people would ask for fixes, features, etc., there might be more...


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Guy Vider
Product Manager
United States United States
Currently, I manage the West Coast Professional Services team for a large company. Part of my job includes implementing solutions and developing "glue" applications.

I love RAD (Rapid Application Development) - specify a problem, come up with the solution, code it - and change later. This is where coding comes closest to art. Just let it flow...

If you want more biographical items, look at my LinkedIn profile at and if you'd like to see my opinion on other tech-related subjects, read my blog at

You may also be interested in...

Comments and Discussions

QuestionNew to c++ Pin
Don_315-Nov-12 4:43
memberDon_315-Nov-12 4:43 
QuestionAbout Restricted User Pin
Anup Pande31-Oct-12 20:32
memberAnup Pande31-Oct-12 20:32 
GeneralMy vote of 5 Pin
itsho3-Mar-12 10:18
memberitsho3-Mar-12 10:18 
QuestionCan't download the code. Is something wrong? Pin
Member 420673427-Feb-09 6:46
memberMember 420673427-Feb-09 6:46 
AnswerRe: Can't download the code. Is something wrong? Pin
Guy Vider27-Feb-09 13:05
memberGuy Vider27-Feb-09 13:05 
Questiondoes this require .net framework? if it does, then how does it work if .net framework isn't there? Pin
cheng_j_zhang30-Nov-08 18:36
membercheng_j_zhang30-Nov-08 18:36 
AnswerRe: does this require .net framework? if it does, then how does it work if .net framework isn't there? Pin
cheng_j_zhang30-Nov-08 18:39
membercheng_j_zhang30-Nov-08 18:39 
GeneralRe: does this require .net framework? if it does, then how does it work if .net framework isn't there? Pin
Guy Vider30-Nov-08 20:14
memberGuy Vider30-Nov-08 20:14 
AnswerRe: does this require .net framework? if it does, then how does it work if .net framework isn't there? Pin
Guy Vider30-Nov-08 20:11
memberGuy Vider30-Nov-08 20:11 
Generalnot working for me Pin
tomtom198011-Dec-07 2:00
membertomtom198011-Dec-07 2:00 
GeneralStack problems in your code using 2005... Pin
M i s t e r L i s t e r23-Sep-07 19:32
memberM i s t e r L i s t e r23-Sep-07 19:32 
GeneralRe: Stack problems in your code using 2005... Pin
Guy Vider23-Sep-07 19:54
memberGuy Vider23-Sep-07 19:54 
GeneralWhy not check the filesystem Pin
Shane Story6-Jul-07 7:36
memberShane Story6-Jul-07 7:36 
AnswerRe: Why not check the filesystem Pin
Guy Vider6-Jul-07 8:25
memberGuy Vider6-Jul-07 8:25 
GeneralRe: Why not check the filesystem Pin
Shane Story6-Jul-07 11:49
memberShane Story6-Jul-07 11:49 
AnswerRe: Why not check the filesystem Pin
Guy Vider6-Jul-07 12:37
memberGuy Vider6-Jul-07 12:37 
Question.NET on Vista Pin
GaryJForeman3-May-07 3:28
memberGaryJForeman3-May-07 3:28 
AnswerRe: .NET on Vista Pin
gvider3-May-07 5:47
membergvider3-May-07 5:47 
GeneralAlternative is VS 2005 'Setup Project' Pin
Cormac M Redmond27-Apr-07 14:17
memberCormac M Redmond27-Apr-07 14:17 
GeneralRe: Alternative is VS 2005 'Setup Project' Pin
gvider28-Apr-07 8:17
membergvider28-Apr-07 8:17 
GeneralRe: Alternative is VS 2005 'Setup Project' Pin
Cormac M Redmond28-Apr-07 18:28
memberCormac M Redmond28-Apr-07 18:28 
GeneralSome other references to check out Pin
Scott Dorman27-Apr-07 5:00
memberScott Dorman27-Apr-07 5:00 
GeneralRe: Some other references to check out Pin
gvider28-Apr-07 8:19
membergvider28-Apr-07 8:19 
GeneralI like it, it's perfect, now fix it Pin
codification26-Apr-07 18:07
membercodification26-Apr-07 18:07 
GeneralRe: I like it, it's perfect, now fix it Pin
gvider28-Apr-07 8:23
membergvider28-Apr-07 8:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170117.1 | Last Updated 26 Apr 2007
Article Copyright 2007 by Guy Vider
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid