Question

I have a launcher/updater application written for .NET 2.0 that needs to check if the user has XNA 4.0 installed.

If it's not, then user is asked to install it.

How to do it?

No correct solution

OTHER TIPS

Here is a function I wrote to do this:

    public string CheckXNAFramework(out bool ok)
    {
        string output = "";

        string baseKeyName = @"SOFTWARE\Microsoft\XNA\Game Studio";
        Microsoft.Win32.RegistryKey installedFrameworkVersions = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(baseKeyName);

        string[] versionNames = installedFrameworkVersions.GetSubKeyNames();

        bool found = false;
        foreach (string s in versionNames)
        {
            if (s == "v4.0")
            {
                found = true;
                break;
            }
        }
        if (found)
        {
            output += "Microsoft XNA Framework found successfully.\n";
            ok = true;
        }
        else
        {
            output += "Correct version of the Microsoft XNA Framework not found. Please install version 4.0 or higher.\n";
            ok = false;
        }

        return output;
    }

Alright, so I would say the easiest way to find if version 4.0 of xna is installed would be to look for the registry key. Look at this bytes forum for an example of how to do it.

Also, as stated in my comments, this isn't the best solution because C# runtime isn't very widespread, meaning that your installer might not even work. Try the oneclick installer or something similar (like the InnoInstaller).

EDIT: Feel stupid, this the the registry key to look for: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v4.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top