我需要替换目标机器上现有的 .json 文件。
我在我的套件中以提升的权限将其作为事件/动作执行。
这是脚本:
try
{
$ProductName = "ravendb"
$Product = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $ProductName}
if ($Product)
{
stop-service RavenDB
(Get-Service RavenDB).WaitForStatus('Stopped', '00:00:30')
$Folder = 'C:\RavenDB-4.2.x\Server'
Copy-Item -Path "settings.json" -Destination $Folder -force
start-service RavenDB
(Get-Service RavenDB).WaitForStatus('Running', '00:00:30')
exit(0)
}
else
{
exit(1)
}
}
catch {
$StringValue = resolve-suitestring -StringId $_.Exception.Message
trace-suiteinfo -LogMessage $StringValue
exit(1)
}
但是文件实际上并没有被覆盖。虽然正在停止/重新启动服务。 手动运行脚本(使用旁路执行策略)工作正常。
套件调试日志表明没有错误:
2-25-2023[01:26:47 PM]: Running event 'update-ravendb-settings'
2-25-2023[01:26:47 PM]: Engine: request for proxy handler, 0, 0
2-25-2023[01:26:48 PM]: (PowerShell Action): Attempting to load through CLR 4 APIs...
2-25-2023[01:26:48 PM]: (PowerShell Action): Getting meta host...
2-25-2023[01:26:48 PM]: (PowerShell Action): Enumerating available runtimes...
2-25-2023[01:26:48 PM]: (PowerShell Action): Highest available runtime: v4.0.30319
2-25-2023[01:26:48 PM]: (PowerShell Action): Trying to use highest runtime...
2-25-2023[01:26:48 PM]: (PowerShell Action): Using highest version runtime...
2-25-2023[01:26:57 PM]: Action returned value 0x00000000
2-25-2023[01:26:57 PM]: Action 'update-ravendb-settings' returned status 0x00000000
为什么我的脚本在 Installhield 套件中作为动作/事件调用时不起作用?