none
How do I test if the .NET Framework is installed on the customer's computer?

    Question

  • Hello,

    I have a WPF .NET 4 program that will be running off of a USB flash drive.  And it is set to auto-start when the flash drive is inserted into the port.  The problem is, if the customer does not have .NET 4 installed,the ugly message below pops up:

    Title bar: MyProgram.EXE - .NET framework Initialization Error
    Body: To run this application, you first must install one of the following versionse of the .NET Framework:
    v.4.0.30319
    Contact your application publisher for instructions about obtaining the appropriate version of the .NET Framework.
    Button: OK

    This is very unacceptable.  I need to present a much better message to the user as well as buttons to click that will automate the installation of the appropriate .NET framework.

    How do I test if the .NET Framework is installed on the customer's computer?

    I'm hoping that I don't need a separate program for this test, for then I'd have to have that program start first each and every time and if the appropriate .NET framework is present, it will start MyProgram.

    Regards,

    Robert

    Wednesday, September 08, 2010 5:43 PM

Answers

  • 1) no .NET framework? Do you really have to support machines that old?

    you wont even be able to run a .NET program on a machine without the framework. 

     

    In your case you need a non .NET solution.

     

    1) Probably the best solution would be to check the registry:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

     

    The link below might do this already in c++.  Did not test it, nor no how safe the page or code is.

    http://community.bartdesmet.net/blogs/bart/archive/2005/07/27/3172.aspx

     

    PS: This isn't really a WPF question :).

    Wednesday, September 08, 2010 7:21 PM
  • Hi R-F-M,

    As far as I know, the answer to your question 1) and 2) should be No, it will not run. I think you will need something like a seperate c++ appliaction to achieve what you want as KP_SES has suggested.

    Best regards,

    Min


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, September 13, 2010 2:58 AM
    Moderator

All replies

  • using System;
    
    class Version
    {
     public static void Main()
     {
      Console.WriteLine();
      Console.WriteLine(".Net Framework Version {0}",
        Environment.Version.ToString());
     }
    }
    

    My .NET Blog: http://michaelcrump.net
    Wednesday, September 08, 2010 6:22 PM
  • Hello Michael,

    Thanks for your reply.  In my search on the WEB for the answer, it seems that the environment variable is not a reliable place to get the .NET Framework version because it only holds one version, not all the versions available.  And perhaps there is no guarantee that the version in that environment variable is the latest version currently installed on their computer.

    But a possible even bigger problem, is if your program is compiled against a .NET framework not installed on the user computer, it will give me the message indicated in my first post.  I'm not sure about that, but will that program run if the user does not have any .NET Frameworks installed?

    Regards,

    Robert

    Wednesday, September 08, 2010 6:31 PM
  • System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion
    Wednesday, September 08, 2010 6:38 PM
  • Hello KP_SES,

    Thanks for your input, and I just did a cursory search on the internet without success of determining:

    1) If no .NET platform is installed on the computer, with the program containing "GetSystemVersion" even run?

    2) If the program containing "GetSystemVersion" was compiled in a newer version of the.NET Framework than is installed on the user's computer, will the program run?

    3) In either of the above two case, if it does run till a certain point, where does the "GetSystemVersion" have to be so that it is executed before the program crashes?

    I there a list of things one can do in a .NET program running on a computer with an older version of the .NET Framework installed or no version at all installed?

    Regards,

    Robert

     

    Wednesday, September 08, 2010 6:51 PM
  • 1) no .NET framework? Do you really have to support machines that old?

    you wont even be able to run a .NET program on a machine without the framework. 

     

    In your case you need a non .NET solution.

     

    1) Probably the best solution would be to check the registry:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

     

    The link below might do this already in c++.  Did not test it, nor no how safe the page or code is.

    http://community.bartdesmet.net/blogs/bart/archive/2005/07/27/3172.aspx

     

    PS: This isn't really a WPF question :).

    Wednesday, September 08, 2010 7:21 PM
  • Hi R-F-M,

    As far as I know, the answer to your question 1) and 2) should be No, it will not run. I think you will need something like a seperate c++ appliaction to achieve what you want as KP_SES has suggested.

    Best regards,

    Min


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, September 13, 2010 2:58 AM
    Moderator