NSIS导入带参数的PowerShell模块

时间:2016-08-29 09:58:25

标签: nsis powershell-v4.0

我编写了一个示例程序,它将编写Hello World并创建NSIS文件,并执行该文件对我来说很好

我的.nsi脚本如下

!include "x64.nsh"

Name "nsExec Test"
OutFile "nsExecTest.exe"
#ShowInstDetails show

Section "Output to variable"
nsExec::ExecToStack 'powershell.exe "& "Import-Module C:\PowerShell\Hello.psm1"'
Pop $0
Pop $1
DetailPrint '"ImportModules" printed: $1'
SectionEnd

当我执行时,按照写入的方式打印写入主机

我在.psm1档案中的代码

# Filename: Hello.psm1
Write-Host
Write-Host 'Hello World!'
Write-Host "Good-bye World! `n"
# end of script

现在我试图用参数实现相同的功能,有人可以帮助我

# Filename: TestParameter.psm1
function TestParam([string] $TestParam)
{
    Write-Host
    Write-Host '$TestParam'
    Write-Host "Good-bye $TestParam! `n"
}
# end of script

1 个答案:

答案 0 :(得分:0)

而不是模块,如何使用普通脚本?

C:\PowerShell\script1.ps1

param([string]$TestParam)

Write-Host
Write-Host '$TestParam'
Write-Host "Good-bye $TestParam! `n"

然后在nsi

nsExec::ExecToStack 'powershell.exe "& "C:\PowerShell\script.ps1 -TestParam myString"'