fox
fox

Reputation: 1

Detect and install framework 4.5 when program execute

I have VS2013 EE WinForms application with target .net 4.5. When I try to execute my app under Win7 without 4.5 framework installed exception window appears (0xc000007b). What should I set in my app settings for showing a good info window with download framework option? I don't want to publish installation file, just want exe with dll-s so publish is not my target.

Upvotes: 0

Views: 146

Answers (2)

raanubis
raanubis

Reputation: 11

try:

http://thecodeventures.blogspot.com/2012/12/c-how-to-check-if-specific-version-of.html

reffers to msdn

http://msdn.microsoft.com/en-us/library/hh925568.aspx

    private static void Get45or451FromRegistry()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) {
    int releaseKey = Convert.ToInt32(ndpKey.GetValue("Release"));
    if (true) {
        Console.WriteLine("Version: " + CheckFor45DotVersion(releaseKey));
    }
}
}
// Checking the version using >= will enable forward compatibility,  
// however you should always compile your code on newer versions of 
// the framework to ensure your app works the same. 

private static string CheckFor45DotVersion(int releaseKey){
if ((releaseKey >= 379893)) {
    return "4.5.2 or later";
}
if ((releaseKey >= 379675)) {
    return "4.5.1 or later";
}
if ((releaseKey >= 378389)) {
    return "4.5 or later";
}
// This line should never execute. A non-null release key should mean 
// that 4.5 or later is installed. 
return "No 4.5 or later version detected";
}

kind regards

Upvotes: 1

V2Solutions - MS Team
V2Solutions - MS Team

Reputation: 1127

you can check in registry which framework is installed ? If VS version is below to 4.5 give a message window to download that version.

you can easily find out how to check VS version installed ?

here is the link http://www.mztools.com/articles/2008/MZ2008003.aspx

Upvotes: 0

Related Questions