![如何检查服务是否存在,如果存在,则使用 CMD 执行命令](https://linux22.com/image/1594201/%E5%A6%82%E4%BD%95%E6%A3%80%E6%9F%A5%E6%9C%8D%E5%8A%A1%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%A6%82%E6%9E%9C%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%88%99%E4%BD%BF%E7%94%A8%20CMD%20%E6%89%A7%E8%A1%8C%E5%91%BD%E4%BB%A4.png)
windows-service
如果存在的话我想执行以下命令:
myservice.exe uninstall
myservice
我的 Windows 服务名称在哪里?
我努力了:
$serviceName = 'simpleservice'
If (Get-Service $serviceName -ErrorAction SilentlyContinue) {
If ((Get-Service $serviceName).Status -eq 'Running') {
Stop-Service $serviceName
Write-Host "Stopping $serviceName"
} Else {
Write-Host "$serviceName found, but it is not running."
}
path\to\my\service\$serviceName uninstall
} Else {
Write-Host "$serviceName not found"
}