我运行了一个Windows服务,并给出了可执行文件的路径(右键单击服务 - >属性 - >可执行文件的路径)
"abc.exe" -s "cdf.conf"
我正在尝试使用powershell自动安装此服务。我应该使用conf文件提供完整的服务.exe吗?
$ abcService =“?????”
$Proc = Start-Process $abcService $exeArgs -WorkingDirectory "D:\abc\" -ErrorAction SilentlyContinue
我应该如何使用-s向.exe输入配置文件?有帮助吗?还是建议?可能是次要的,但它对我来说是个新手。
我正在尝试将其作为服务运行。
这就是我正在做的事情
$abcservice = "D:\abc\abc.exe"
$abcserviceName = "abc"
function InstallABCservice(){
Write-Host "Installing $abcserviceName"
$argList = "/s D:\abc\abc.conf"
$Proc = Start-Process $abcservice $argList -WorkingDirectory "D:\abc\" -ErrorAction SilentlyContinue
Write-Host "Install running under process id $($Proc.Id). Waiting 5 seconds"
Start-Sleep -s 5
if ($Proc -ne $null){
Stop-Process -Id $Proc.Id -ErrorAction SilentlyContinue
}
Write-Host "Install should be complete. Checking for service $abcservice"
$abcsvc = gwmi win32_service -filter "name='$abcserviceName'"
if ($abcsvc -eq $null) {
throw "Service $abcserviceName does not exist. The automated install process failed. A manual install will be required"
}
Write-Host "Found service $abcserviceName. Changing startup-type to Disabled"
Set-Service $abcserviceName -startuptype "Disabled"
$abcsvc.change($null,$null,$null,$null,$null,$null,$null,$null,$null,$null,$null)
Write-Host "Startup-type changed to Disabled"
Write-Host "Install successfully complete. Service $($abcsvc.DisplayName) installed and startup type set to Disabled"
}
function Main(){
InstallABCservice
}
Main
答案 0 :(得分:1)
如果您只是想通过一些参数自动启动一个进程;然后你可以做到以下几点:
$service = "c:\path\abc.exe";
$arguments= "/s c:\test\myconf.conf"
$proc = Start-Process $service $arguments -WorkingDirectory "D:\abc\" -ErrorAction SilentlyContinue
如果您要注册服务(因此它显示在services.msc或get-services下),因此您可以使用start-service / stop-service cmdlet,那么您需要先注册该服务:
将exe注册为服务(windows):
sc.exe create <new_service_name> binPath= "<path_to_the_service_executable>"
取消注册/卸载服务:
sc delete <servicename>
有关安装/处理服务的更多信息: https://technet.microsoft.com/en-us/library/cc754599.aspx
如果你已经安装了exe作为服务;通过get-service,stop-service,start-service和restart-service来操作它。
Get-service将为您提供正在运行的服务的状态。
希望这能解释你的需要;因为你的问题是暧昧的