0

Possible Duplicate:
NSIS installer that checks for .NET Framework

How do I find out if the correct .Net version is installed during installation using NSIS?

Community
  • 1
  • 1
meffordm
  • 469
  • 1
  • 6
  • 15
  • Hi meffordm. It is fine to answer your own question, but you should do it in a Jeopardy style. So actually ask the question and then post the answer. just posting an answer as a question is against site etiquette. [Etiquette for answering your own question](http://meta.stackexchange.com/questions/17845/etiquette-for-answering-your-own-question) – Matt Ellen Jul 21 '11 at 21:43
  • SO is not the correct place for this kind of code, post it on the NSIS wiki. Also, just checking the NDP key does not cover every .net version... – Anders Jul 22 '11 at 16:11
  • @Matt Ellen - Thanks Matt. I thought about that after I posted this. – meffordm Jul 22 '11 at 22:08
  • @Anders - I tried to post it there, but I couldn't figure out how to create a new page on their wiki. Maybe if I have some time this weekend I'll take care of it. Also, I thought the NDP key covered them all. Where else should I look? – meffordm Jul 22 '11 at 22:10
  • @Anders - I found on [this MSDN page](http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785) that the NDP key covers most of them. It also says how to determine if any of the current and previous versions are installed. Now I just need to implement these changes. Thanks for the heads up. – meffordm Jul 23 '11 at 04:17
  • @meffordm: To create a new wiki page, just navigate to a url on the wiki that does not exist... – Anders Jul 23 '11 at 15:12

1 Answers1

0

I found a few ways to check for the required .NET Framework version while using NSIS to install an .EXE, but they either didn't work for me or they were too complex. So, I wrote one, or heavily modified one I found on the NSIS wiki. Here it is for anyone to use if they need it. If it needs some work, please let me know so we can keep it updated. Thanks.

/*
 * Name: CheckDotNetFramework.nsh
 * Version: 0.1
 * Date: 20110720
 *
 * Author: Michael Mefford
 * Contact info: meffordm@gmail.com
 *
 * Description: NSIS header file to check a windows system for a specified .NET
 *              framework.  CheckDotNetFramework.nsh uses the NSIS stack to
 *              receive and pass values.
 *
 * Modified from: http://nsis.sourceforge.net/How_to_Detect_any_.NET_Framework
 *
 * License: Copyright (C) 2011  Michael Mefford
 *
 *          This software is provided 'as-is', without any express or implied
 *          warranty. In no event will the author(s) be held liable for any
 *          damages arising from the use of this software.
 *
 *          Permission is granted to anyone to use this software for any
 *          purpose, including commercial applications, and to alter it and
 *          redistribute it freely, subject to the following restrictions:
 *
 *             1. The origin of this software must not be misrepresented;
 *                you must not claim that you wrote the original software.
 *                If you use this software in a product, an acknowledgment in
 *                the product documentation would be appreciated but is not
 *                required.
 *
 *             2. Altered versions must be plainly marked as such,
 *                and must not be misrepresented as being the original software.
 *
 *             3. This notice may not be removed or altered from any
 *                distribution.
 *
 * Usage: Push ${DotNetFrameworkVersion}
 *        Call CheckDotNetFramework
 *        Exch $R0
 *        StrCmp $R0 "0" found not_found
 *
 * Algorithm: ...
 *
 * Input: A .NET Framework version.  This must be verbatim, including major,
 *        minor, and build version - i.e.
 *
 *          1.1.4322
 *          2.0.50727
 *          3.0
 *          3.5
 *          4
 *          4.0
 *          .
 *          .
 *          .
 *          etc.
 *
 * Output: "0" if the requested .Net Framework version IS FOUND
 *         "1" if the requested .NET Framework version IS NOT FOUND
 *
 */

Function CheckDotNetFramework

  /* Exchange $R0 with the top of the stack to get the value passed by caller */
  Exch $R0

  /* Save other NSIS registers */
  Push $R1
  Push $R2
  Push $R3

  /* Zero out $R2 for the indexer */
  StrCpy $R2 "0"

loop:
  /* Get each sub key under "SOFTWARE\Microsoft\NET Framework Setup\NDP" */
  EnumRegKey $R1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP" $R3
  StrCmp $R1 "" version_not_found  /* Requested version is not found */

  StrCpy $R2 $R1 "" 1              /* Remove "v" from subkey */
  StrCmp $R2 $R0 version_found     /* Requested version is found */

  IntOp $R3 $R3 + 1                /* Increment registry key index */
  Goto loop

/* The requested .Net Framework version WAS NOT FOUND on this system */
version_not_found:
  /* Restore the registers saved earlier */
  Pop $R3
  Pop $R2
  Pop $R1
  Pop $R0

  Push "1"  /* Put "1" on the top of the stack for caller to use */
  Goto end

/* The requested .Net Framework version WAS FOUND on this system */
version_found:
  /* Restore the registers saved earlier */
  Pop $R3
  Pop $R2
  Pop $R1
  Pop $R0

  Push "0"  /* Put "0" on the top of the stack for caller to use */

end:

FunctionEnd
meffordm
  • 469
  • 1
  • 6
  • 15