maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherit...@apache.org
Subject svn commit: r468820 - /maven/maven-1/core/trunk/src/installer/nsis/Environment.nsh
Date Sun, 29 Oct 2006 02:26:53 GMT
Author: aheritier
Date: Sat Oct 28 19:26:52 2006
New Revision: 468820

URL: http://svn.apache.org/viewvc?view=rev&rev=468820
Log:
Fix environment script.
Set env vars in system only i the user is admin

Modified:
    maven/maven-1/core/trunk/src/installer/nsis/Environment.nsh

Modified: maven/maven-1/core/trunk/src/installer/nsis/Environment.nsh
URL: http://svn.apache.org/viewvc/maven/maven-1/core/trunk/src/installer/nsis/Environment.nsh?view=diff&rev=468820&r1=468819&r2=468820
==============================================================================
--- maven/maven-1/core/trunk/src/installer/nsis/Environment.nsh (original)
+++ maven/maven-1/core/trunk/src/installer/nsis/Environment.nsh Sat Oct 28 19:26:52 2006
@@ -3,22 +3,6 @@
  
 !include WinMessages.nsh
 
-!ifndef WriteEnvStr_RegKey
-; register environment variables in the system scope if the user has admin rights
-System::Call "kernel32::GetModuleHandle(t 'shell32.dll') i .s"
-System::Call "kernel32::GetProcAddress(i s, i 680) i .r0"
-System::Call "::$0() i .r0"
-StrCmp $0 "" 0 IsAdmin IsNotAdmin
-IsAdmin:
-!define WriteEnvStr_RegKey \
-       'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
-Goto Registry_ok
-IsNotAdmin:
-!define WriteEnvStr_RegKey 'HKCU "Environment"'
-Goto Registry_ok
-Registry_ok:
-!endif
- 
 #
 # WriteEnvStr - Writes an environment variable
 # Note: Win9x systems requires reboot
@@ -47,7 +31,12 @@
     Goto WriteEnvStr_done
  
   WriteEnvStr_NT:
-      WriteRegExpandStr ${WriteEnvStr_RegKey} $0 $1
+      Call IsAdmin
+      Pop $2
+      StrCmp $2 1 +3
+      WriteRegExpandStr HKCU "Environment" $0 $1
+      Goto +2
+      WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$0 $1
       SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
         0 "STR:Environment" /TIMEOUT=5000
  
@@ -103,7 +92,12 @@
       Goto DeleteEnvStr_done
  
   DeleteEnvStr_NT:
-    DeleteRegValue ${WriteEnvStr_RegKey} $0
+    Call un.IsAdmin
+    Pop $1
+    StrCmp $1 1 +3
+    DeleteRegValue HKCU "Environment" $0
+    Goto +2
+    DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" $0
     SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} \
       0 "STR:Environment" /TIMEOUT=5000
  
@@ -152,5 +146,33 @@
  
 !endif ; IsNT_KiCHiK
  
-!endif ; _WriteEnvStr_nsh 
- 
\ No newline at end of file
+#
+# [un.]IsAdmin - Pushes 1 if users has admin rights, 0 if not
+#
+# Example:
+#   Call IsAdmin
+#   Pop $0
+#   StrCmp $0 1 +3
+#     MessageBox MB_OK "You are not administrator!"
+#     Goto +2
+#     MessageBox MB_OK "You are administrator!"
+#
+!macro IsAdmin UN
+Function ${UN}IsAdmin
+  Push $0
+  System::Call "kernel32::GetModuleHandle(t 'shell32.dll') i .s"
+  System::Call "kernel32::GetProcAddress(i s, i 680) i .r0"
+  System::Call "::$0() i .r0"
+  StrCmp $0 "" 0 +4
+  Pop $0
+  Push 0
+  Return
+  Pop $0
+  Push 1
+  Return
+FunctionEnd
+!macroend
+!insertmacro IsAdmin ""
+!insertmacro IsAdmin "un."
+
+!endif ; _WriteEnvStr_nsh
\ No newline at end of file



Mime
View raw message