...and of course I forgot the patch. Here it is.
Mattias

On Wed, Feb 1, 2012 at 12:06 AM, Mattias Helsing <[email protected]> wrote:
> Hi,
>
> I'm a user of the NSIS generator of CPack to generate nice windows
> installers. Often lately I have embedded external installers with my
> installer and then run them as part of my installer. This is working
> really nice except for one thing; if you need to install drivers or
> services the entire installer will require admin or power user
> privileges. Thus I need to stop both the installer and the uninstaller
> from running early if the user running it doesn't have proper
> privileges. Until now I have manually post edited the generated
> project.nsi file to add this functionlity and regenerated the
> installer.
> Now I hope that someone else is embedding external installers with
> their installers and propose a new feature. It optionally adds an
> abort message and installer abort if one sets
> CPACK_NSIS_REQUIRE_POWERUSER prior to include(CPack).
> Attached patch is against cmake master. In CPack.cmake it sets
> CPACK_NSIS_REQUIRE_POWERUSER to "ON" if a user have defined or set
> CPACK_NSIS_REQUIRE_POWERUSER to anything. This is because the NSIS
> scripting language is assembler-like and I string compare (StrCmp) the
> value of said variable to "ON" to perform a relative jump. Not setting
> CPACK_NSIS_REQUIRE_POWERUSER will generate the same installer as
> NSIS.template.in has generated since cmake 2.6. Feedback welcome.
>
> cheers
> Mattias
diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake
index 2cc27cf..e167815 100644
--- a/Modules/CPack.cmake
+++ b/Modules/CPack.cmake
@@ -300,6 +300,9 @@ cpack_set_if_not_set(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
 IF(CPACK_NSIS_MODIFY_PATH)
   SET(CPACK_NSIS_MODIFY_PATH ON)
 ENDIF(CPACK_NSIS_MODIFY_PATH)
+IF(CPACK_NSIS_REQUIRE_POWERUSER)
+  SET(CPACK_NSIS_REQUIRE_POWERUSER ON)
+ENDIF(CPACK_NSIS_REQUIRE_POWERUSER)
 
 SET(__cpack_system_name ${CMAKE_SYSTEM_NAME})
 IF(${__cpack_system_name} MATCHES Windows)
diff --git a/Modules/NSIS.template.in b/Modules/NSIS.template.in
index 6259a5b..11e9abc 100644
--- a/Modules/NSIS.template.in
+++ b/Modules/NSIS.template.in
@@ -757,6 +757,9 @@ Function un.onInit
     Goto done
     
   noLM:
+    StrCmp "@CPACK_NSIS_REQUIRE_POWERUSER@" "ON" 0 +3
+    MessageBox MB_OK "You need to be logged in as an administrator user to install @CPACK_NSIS_PACKAGE_NAME@"
+    Abort "You need to be logged in as an administrator user to install @CPACK_NSIS_PACKAGE_NAME@"
     ;Get installation folder from registry if available
 
   done:
@@ -934,6 +937,10 @@ Function .onInit
     Goto done
     
   noLM:
+    StrCmp "@CPACK_NSIS_REQUIRE_POWERUSER@" "ON" 0 +3
+    MessageBox MB_OK "You need to be logged in as an administrator user to install @CPACK_NSIS_PACKAGE_NAME@"
+    Abort "You need to be logged in as an administrator user to install @CPACK_NSIS_PACKAGE_NAME@"
+
     StrCpy $SV_ALLUSERS "AllUsers"
     ;Get installation folder from registry if available
 
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to