Проверьте требуемую версию .NET с помощью NSIS

Возможный дубликат:
установщик NSIS, который проверяет наличие .NET Framework

Как узнать, установлена ​​ли правильная версия .Net во время установки с помощью NSIS?


person meffordm    schedule 21.07.2011    source источник
comment
Привет, meffordm. Ответить на свой вопрос - это нормально, но вы должны делать это в стиле Jeopardy. Так что задайте вопрос, а затем отправьте ответ. просто опубликовать ответ в качестве вопроса - это нарушение этикета сайта. Этикет при ответе на свой вопрос   -  person Matt Ellen    schedule 22.07.2011
comment
ТАК не подходящее место для такого кода, разместите его в вики NSIS. Кроме того, простая проверка ключа NDP не распространяется на все версии .net ...   -  person Anders    schedule 22.07.2011
comment
@ Мэтт Эллен - Спасибо, Мэтт. Я подумал об этом после того, как разместил это.   -  person meffordm    schedule 23.07.2011
comment
@Anders - Я пытался разместить это там, но не мог понять, как создать новую страницу на их вики. Может, если у меня будет немного времени в эти выходные, я позабочусь об этом. Кроме того, я думал, что ключ NDP покрывает их все. Где еще мне посмотреть?   -  person meffordm    schedule 23.07.2011
comment
@Anders - на этой странице MSDN я обнаружил клавиша NDP охватывает большинство из них. В нем также говорится, как определить, установлена ​​ли какая-либо из текущей или предыдущей версии. Теперь мне просто нужно внести эти изменения. Спасибо за внимание.   -  person meffordm    schedule 23.07.2011
comment
@meffordm: Чтобы создать новую страницу вики, просто перейдите по URL-адресу вики, который не существует ...   -  person Anders    schedule 23.07.2011


Ответы (1)


Я нашел несколько способов проверить требуемую версию .NET Framework при использовании NSIS для установки .EXE, но они либо не работали для меня, либо были слишком сложными. Итак, я написал один или сильно модифицировал тот, который нашел в вики NSIS. Вот он, чтобы любой мог использовать, если ему это нужно. Если потребуется доработка, дайте мне знать, чтобы мы могли держать его в курсе. Спасибо.

/*
 * Name: CheckDotNetFramework.nsh
 * Version: 0.1
 * Date: 20110720
 *
 * Author: Michael Mefford
 * Contact info: [email protected]
 *
 * 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
person meffordm    schedule 22.07.2011