Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 启动进程无法启动服务_Powershell_Start Process - Fatal编程技术网

Powershell 启动进程无法启动服务

Powershell 启动进程无法启动服务,powershell,start-process,Powershell,Start Process,我是powershell的新手。我正在编写一个脚本,它不会间歇性地启动服务 $sensuresult = Start-Process -Wait -FilePath $filepath -ArgumentList '/tasks="assocfiles,modpath" /quiet' -PassThru 基本上,我们正在尝试安装一个.msi包。上述线路间歇性故障 Write-Host $sensuresult Write-Host : The following exception occ

我是powershell的新手。我正在编写一个脚本,它不会间歇性地启动服务

$sensuresult = Start-Process -Wait -FilePath $filepath -ArgumentList '/tasks="assocfiles,modpath" /quiet' -PassThru
基本上,我们正在尝试安装一个.msi包。上述线路间歇性故障

Write-Host $sensuresult

Write-Host : The following exception occurred while retrieving the string: "Process has exited, so 
the requested information is not available."
At line:8 char:1
+ Write-Host $sensuresult
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Write-Host], ExtendedTypeSystemException
+ FullyQualifiedErrorId : 
ToStringPSObjectBasicException,Microsoft.PowerShell.Commands.WriteHostCommand
有了上面的错误消息,我真的不知道启动进程是失败还是写入主机


我可以了解一下为什么启动进程不间歇安装软件包,以及最好的替代方法是什么。

您可以通过首先检查进程是否正在运行来启动进程

#check service is running or not

$ServiceName = 'AppIDSvc'
$arrService = Get-Service -Name $ServiceName

while ($arrService.Status -ne 'Running')
{

    Start-Service $ServiceName
    write-host $arrService.status
    write-host 'Service starting'
    Start-Sleep -seconds 15
    $arrService.Refresh()
    if ($arrService.Status -eq 'Running')
    {
        Write-Host 'Service is now Running'
    }

}

我有类似的逻辑来启动服务,该服务将在安装.msi二进制文件后提供。我想先安装我的二进制文件。@Ashwin,好的,通常当你尝试运行msi时,哪个exe正在运行,因为安装包都附带了.msi,需要知道哪个像PkgMgr.exe或wsua.exe或其他什么吗?我正在尝试安装'sensu'