在NSIS中我想执行一个cmd /批处理文件,该文件仅为没有管理权限的本地用户创建桌面快捷方式。NSIS - 当RequestExecutionLevel管理员不够时,如何将管理员级别继承到ExecShell?
问题是,如果cmd以管理员身份运行,并且在NSIS中尽管RequestExecutionLevel admin
ExecShell
没有继承足够的特权,但因为我收到错误消息,主cmd命令(query.exe) “查询无法找到”。如果没有管理员权限运行cmd,就会发生这种情况
有没有人知道我在执行cmd文件时做错了什么?或者,有没有人知道比cmd文件更好的方式来为用户的桌面创建快捷方式?
感谢您的帮助提前。
这里的CMD文件:
for /f "tokens=1 delims=> " %%a in ('query user ^| findstr /C:"console"') do SET USERNAME=%%a
mklink "C:\users\%USERNAME%\Desktop\7Zip Filemanager" "%programfiles%\7-zip\7zFM.exe"
这是我的NSIS文件:
;------------------------------------
; Creates desktop shortcuts for the local user instead
; for that user that runs this installer (admin).
; ($DESKTOP references to the user that runs this installer)
;------------------------------------
;------------------------------------
;Includes
!include "MUI.nsh"
!include "LogicLib.nsh"
!define MUI_ABORTWARNING # This will warn the user if he exits from the installer.
;------------------------------------
;Pages of installer
!insertmacro MUI_PAGE_WELCOME # Welcome to the installer page.
!insertmacro MUI_PAGE_INSTFILES # Installing page.
!insertmacro MUI_PAGE_FINISH # Finished installation page.
;------------------------------------
;CRC check
CRCCheck On
;------------------------------------
;Language
!insertmacro MUI_LANGUAGE "English"
;------------------------------------
;Execution level
RequestExecutionLevel admin
;------------------------------------
;Check string length
!define STRING_LENGTH ${NSIS_MAX_STRLEN}
;------------------------------------
;Define the source files for the installer
!define MUI_PRODUCT "SHORTCUTS TEST" #Name of application
!define MUI_FILE_SHORTCUTS_CMD "shortcuts.cmd" #Source of further installation files
!define CMD_SHORTCUTS "$INSTDIR\${MUI_FILE_SHORTCUTS_CMD}"
;------------------------------------
;Define the destinations
Name "${MUI_PRODUCT}" # Name of the installer (usually the name of the application to install).
OutFile "${MUI_PRODUCT} Installer.exe" # Name of the installer's file.
InstallDir "C:\Test\${MUI_PRODUCT}" # Default installing folder ($PROGRAMFILES is Program Files folder).
ShowInstDetails show # This will always show the installation details.
;------------------------------------
;Installer section
Section "Install"
;Create directories:
CreateDirectory $INSTDIR
;Add files
SetOutPath $INSTDIR
File "${MUI_FILE_SHORTCUTS_CMD}" #Move file
;Create shortcuts at user desktop:
;(cmd file needs to be run as administrator,
; otherwise the shortcut is created in the wrong desktop.)
ExecShell "open" '${CMD_SHORTCUTS}' ${SW_SHOW}
SectionEnd
;eof