execute Powershell in NSIS



我遇到以下问题:
我正在尝试在NSIS中使用PowerShell脚本,但是如果我在那里启动安装程序,则弹出PowerShell窗口,但立即关闭。我只能看到PowerShell会打印出错误(一些红色字母(,但是我看不出错误立即关闭。

我所做的所有脚本都是通过替换替换模板中的占位符。" currentpc currentusername",带有命令'whoami'的输出,最后,我每个'schtask'将此XML文件导入任务调度程序。

如果我单独运行脚本,则根据需要工作,但是如果我使用编译设置,则我描述的问题会发生。

当然,我花时间寻找解决方案。
我尝试了以下内容:

  • 我在脚本中的检查中构建,以查看它是否以32位运行。如果是,请重新启动64位

  • 我为我的.xml-template保留

  • 的路径做了一个硬编码的" CD">
  • 我通过'execwait','ns :: exectolog'和'ns :: exectostack'

  • 执行了NSIS内部的PowerShell。

我不知道该怎么办。我希望有人可以提供帮助。

对于那些想阅读代码的人:
这就是我在NSIS中使用脚本的方式:

File ProcessControlTemplateFill.ps1
ExecWait 'powershell -inputformat none -ExecutionPolicy RemoteSigned -File ".ProcessControlTemplateFill.ps1"'

这是我的.ps1-script:

    #############################################################################
#If Powershell is running the 32-bit version on a 64-bit machine, we 
#need to force powershell to run in 64-bit mode .
#############################################################################
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
    write-warning "Y'arg Matey, we're off to 64-bit land....."
    if ($myInvocation.Line) {
        &"$env:WINDIRsysnativewindowspowershellv1.0powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
    }else{
        &"$env:WINDIRsysnativewindowspowershellv1.0powershell.exe" -NonInteractive -NoProfile -file "$($myInvocation.InvocationName)" $args
    }
exit $lastexitcode
}

write-host "Main script body"
#############################################################################
#End
############################################################################# 
cd C:R15
$WERBINICH = whoami
ForEach($Datei in ls './sources/ProcessControlTemplate.xml') {
    $Zeilen =  Get-Content -Path $Datei.Fullname
    $ZeilenZähler = 1
    foreach($Zeile in $Zeilen)
    {
        $Zeile = $Zeile -replace 'CURRENTPC\CURRENTUSERNAME', "$WERBINICH"
        Write-Host $Zeile
        If($ZeilenZähler -eq 1 ) {
           Out-File -FilePath $Datei.Fullname -InputObject $Zeile -Force
        }
        Else {
            Out-File -FilePath $Datei.Fullname -InputObject $Zeile -Force -Append
        }
        $ZeilenZähler++
    }
}
schtasks /create /f /XML .sourcesProcessControlTemplate.xml /tn ProcessControl

使用完整的路径到ProcessControltemplatefill.ps1,而不是相对路径。在您的PowerShell脚本中使用Start-Sleep -s 10暂停一点,以便您可以读取错误。

最新更新