Exception calling Start with 0 argument(s): The system cannot find the file specified
Quite often, I will find a computer where the service for one of our screen viewing software is having troubles. I have a batch file to fix it, but just trying to speed the whole process up as noticed Powershell accomplishes this faster. I first tried stopping the service and then restarting it. But I know sometimes the service has just stopped, so all it needs is to be started. After a quick bit of research I found a script online that checks to see if a specific service is running or not, if it isn't it'll start it and if it is running already it displays a message on screen saying it was already running. I need to be able to restart the service if it's running, but just start it if it's not running. I altered the script slightly and got this; Powershell $svc = get-service -name icas -computername 70-01 if ($svc.Status -eq "Stopped") {$svc.start()} {Write-Host "Service was stopped but is now starting"} elseif ($svc.status -eq "Running") {$svc.stop()} {$svc.start()} {Write-Host "Service restarted"} But the problem is, I'm getting this error; Powershell elseif : The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:3 char:1 + elseif ($svc.status -eq "Running") {$svc.stop()} {$svc.start()} {Writ ... + ~~~~~~ + CategoryInfo : ObjectNotFound: (elseif:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException After some more research online, most of the time this error is apparently due to an incorrect/missing bracket, but everything looks fine to me. System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at Letter_Trigg.Execution(String strCmdLine) in d:\Xp Xtreme - Hodge life\XPXHL\XPXHL\Letter_Trigg.aspx.cs:line 315 |