2016-05-04 38 views
0

你好,我正在重构一个旧的安装脚本,并遇到UAC插件创建的问题。由于!insertmacro Init "installer".onInit运行两次。 !insertmacro Init "uninstaller"un.onInit函数也是如此。NSIS安装程序.onInit和un.onInit由于UAC运行两次因为UAC

因此,安装程序和卸载程序运行两次,这不是我想要的行为。 I have read that the UAC creates an inner process with elevated permissions,这是因为它接触C:/驱动器所需的,但外部进程也运行安装程序。

由于安装脚本很长,我只能粘贴.onInit函数。整个.nsi脚本可以找到here

注释掉!insertmacro确保.onInit函数运行一次,但不再运行安装程序。那么如何才能使安装程序和卸载程序只运行一次,并具有正确的(管理员)权限?

我明白任何建议或答案:)

Function .onInit 
MessageBox MB_OK "In .onInit" 
    SetShellVarContext all 

    !insertmacro Init "installer" 

    System::Call 'kernel32::CreateMutexA(i 0, i 0, t "Tribler") i .r1 ?e' 

    Pop $R0 
    StrCmp $R0 0 checkinst 

    MessageBox MB_OK "The installer is already running." 
    Abort 

    checkinst: 
    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString" 
    StrCmp $R0 "" done 
    IfFileExists $R0 showuninstdialog done 

    showuninstdialog: 
    MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT} is already installed. $\n$\nClick `OK` to remove the previous version or `Cancel` to cancel this upgrade." /SD IDCANCEL IDOK uninst 
    Abort 

    uninst: 
    ClearErrors 
    ; Laurens (2016-03-29): Retrieve the uninstallString stored in the register. Do NOT use $INSTDIR as this points to the current $INSTDIR var of the INSTALLER, 
    ; which is the default location at this point. 
    ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString" 
MessageBox MB_OK "$R0" 
    ExecWait '"$R0"' ;Do not copy the uninstaller to a temp file 
    ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString" 
    StrCmp $R0 "" done 
    Abort 
    done: 

FunctionEnd 
+0

您在此处粘贴的.onInit代码与您链接的代码不匹配!你链接的代码有一个明确的问题,不能真正知道在这里粘贴的代码没有测试自己是否有问题,但我不打算这样做,直到你澄清我应该测试哪些代码。有关于使用NSIS/UAC插件/ Windows版本的一些信息也将很不错... – Anders

+0

@Anders我在推动并尝试几件事情,而我输入这个。对不起,如果它现在有所不同。考虑链接中我正在运行的当前代码中的代码。另外,我将它构建在Windows 2008 64位服务器上,并在Windows 10机器(也是64位)上测试安装过程。 – Gooey

+0

@Anders我已经撤消了一些我的实验性修改并推送了它们。我现在不会推动它,因为当人们看着它时,它确实令人困惑。 – Gooey

回答

2

您链接到的代码(至少当我看着它时)在.onInit中同时调用了!insertmacro UAC_RunElevated!insertmacro Init "installer",所以难怪它跑了好几次。致电!insertmacro UAC_RunElevated后,您必须始终检查$0,因为您可能需要根据其价值调用Quit

我认为初始化宏是我写的,所以应该正常工作(?))

我个人建议你牺牲完成页面上运行复选框,然后你可能不必使用UAC插件...

+0

感谢您的回答安德斯,我插入了UAC_RunElevated作为测试,看看我做的第一件事是获得额外的权限,也许我可以添加一个检查,看看是否有任何参数,我可以检查作为@idleberg提到。不幸的是,只有!insertmacro Init“安装程序”也会使其运行两次。 – Gooey

+0

我会检查我是否可以在没有UAC插件的情况下按照您的建议来做到这一点,非常感谢您的帮助和建议:) – Gooey

+0

我删除了它,重构了这里和那里的文件,它运行得非常出色。谢谢! – Gooey

1

至于我记得,UAC的插件重新启动的特殊参数的安装程序。您可以使用.onInitGetParametersGetOptions检查这一点,那么显示一条消息,有条件:

# get all commandline parameters 
${GetParameters} $0 

# parse specific option 
${GetOptions} $0 "/UAC:" $1 

# do stuff 
IfErrors 0 +2 
MessageBox MB_OK "No admint" IDOK +2 
MessageBox MB_OK "Admin" 

就个人而言,我会使用LogicLib最后一部分:

# do stuff 
${If} $1 == "" 
    MessageBox MB_OK "Not admin" 
${Else} 
MessageBox MB_OK "Admin" 
${Endif} 
+0

感谢您的建议。我已经添加了建议的行,并且在提升的权限对话框之后的第二次运行中向我展示了第一次运行时的空对话框和'/ UAC:/NCRC'。所以这听起来像我想要后者的情况下,有没有办法检查这个? – Gooey

+0

寻找/ UAC:不是正确的选项。 – Anders