changeset 5536:f7f10f198735

Set blas switch shortcut to run as admin whe installed for all users (Bug #59118) * tools/makeinst-script.sh.in: add ShellLinkSetRunAs functional and call in non local mode
author John Donoghue <john.donoghue@ieee.org>
date Wed, 16 Sep 2020 11:34:15 -0400
parents 9b92b671cbdc
children 15ad3e21dc17
files tools/makeinst-script.sh.in
diffstat 1 files changed, 57 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/makeinst-script.sh.in	Mon Sep 14 09:38:57 2020 -0400
+++ b/tools/makeinst-script.sh.in	Wed Sep 16 11:34:15 2020 -0400
@@ -224,6 +224,55 @@
 !define un.DequoteString '!insertmacro DequoteString "un."'
 
 ######################################################################
+
+# function code from https://nsis.sourceforge.io/IShellLink_Set_RunAs_flag
+
+
+!ifndef IPersistFile
+!define IPersistFile {0000010b-0000-0000-c000-000000000046}
+!endif
+!ifndef CLSID_ShellLink
+!define CLSID_ShellLink {00021401-0000-0000-C000-000000000046}
+!define IID_IShellLinkA {000214EE-0000-0000-C000-000000000046}
+!define IID_IShellLinkW {000214F9-0000-0000-C000-000000000046}
+!define IShellLinkDataList {45e2b4ae-b1c3-11d0-b92f-00a0c90312e1}
+  !ifdef NSIS_UNICODE
+    !define IID_IShellLink \${IID_IShellLinkW}
+  !else
+    !define IID_IShellLink \${IID_IShellLinkA}
+  !endif
+!endif
+
+Function ShellLinkSetRunAs
+  System::Store S
+  Pop \$9
+  System::Call "ole32::CoCreateInstance(g'\${CLSID_ShellLink}',i0,i1,g'\${IID_IShellLink}',*i.r1)i.r0"
+  \${If} \$0 = 0
+    System::Call "\$1->0(g'\${IPersistFile}',*i.r2)i.r0" ;QI
+    \${If} \$0 = 0
+      System::Call "\$2->5(w '\$9',i 0)i.r0" ;Load
+      \${If} \$0 = 0
+        System::Call "\$1->0(g'\${IShellLinkDataList}',*i.r3)i.r0" ;QI
+	\${If} \$0 = 0
+          System::Call "\$3->6(*i.r4)i.r0" ;GetFlags
+          \${If} \$0 = 0
+            System::Call "\$3->7(i \$4|0x2000)i.r0" ;SetFlags ;SLDF_RUNAS_USER
+            \${If} $0 = 0
+              System::Call "\$2->6(w '\$9',i1)i.r0" ;Save
+            \${EndIf}
+          \${EndIf}
+          System::Call "\$3->2()" ;Release
+        \${EndIf}
+        System::Call "\$2->2()" ;Release
+      \${EndIf}
+    \${EndIf}
+    System::Call "\$1->2()" ;Release
+  \${EndIf}
+  Push $0
+  System::Store L
+FunctionEnd
+
+######################################################################
 ; custom options page functions
 
 Var InstallShortcuts
@@ -471,7 +520,14 @@
     echo "CreateShortCut '\$SMPROGRAMS\\GNU Octave $VERSION\$MultiUser.Local\\Bash Shell.lnk' '\$INSTDIR\\cmdshell.bat' '' '' 0" >> $OUTFILE
   fi
   if [ -e $OCTAVE_SOURCE/$OCTAVE_SUBDIR/bin/blas_switch.exe ]; then 
-    echo "CreateShortCut '\$SMPROGRAMS\\GNU Octave $VERSION\$MultiUser.Local\\Blas Switcher.lnk' '\$INSTDIR\\$OCTAVE_SUBDIR\\bin\\blas_switch.exe' '' '' 0" >> $OUTFILE
+   cat >> $OUTFILE << EOF
+    CreateShortCut '\$SMPROGRAMS\\GNU Octave $VERSION\$MultiUser.Local\\Blas Switcher.lnk' '\$INSTDIR\\$OCTAVE_SUBDIR\\bin\\blas_switch.exe' '' '' 0
+    \${If} \$MultiUser.InstallMode != "CurrentUser"
+      Push '\$SMPROGRAMS\\GNU Octave $VERSION\$MultiUser.Local\\Blas Switcher.lnk'
+      Call ShellLinkSetRunAs
+      Pop \$0
+    \${EndIf}
+EOF
   fi
   # if we have documentation files, create shortcuts
   if [ -d $OCTAVE_SOURCE/$OCTAVE_SUBDIR/share/doc/octave ]; then