detox1978
asked on
Windows 7 command script help (n00bie)
Hi All,
I'm trying to make a script that will run an .exe if its not running already. Here are the two commands that start and stop the program.
Start program:
"C:\Program Files (x86)\XBMC\XBMC.exe"
Stop program:
taskkill /IM XBMC.exe
So I need to check if XBMC.exe is running, and if it isn't run the start command, if it is run the stop command.
many thanks.
I'm trying to make a script that will run an .exe if its not running already. Here are the two commands that start and stop the program.
Start program:
"C:\Program Files (x86)\XBMC\XBMC.exe"
Stop program:
taskkill /IM XBMC.exe
So I need to check if XBMC.exe is running, and if it isn't run the start command, if it is run the stop command.
many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry posted at the same time. Mine is the Powershell method. oBdA's is using windows shell. Either should suit your purpose.
GusGallows
Never looked at Powershell before... does it also work like this (see the IF and braces, and case)?
Never looked at Powershell before... does it also work like this (see the IF and braces, and case)?
$path = "C:\Program Files (x86)\XBMC\XBMC.exe"
$result = Get-Process | where {$_.Path -eq $Path}
if ($result -eq $null) {
start-process $path
} else {
$name = $result.name
stop-process -name $name -force
}
ASKER
Neither worked for me.
RThe example with the calc did,but when i removed it for the .exe it didn't.
Not sure why the powershell didn't work, it returned this error message;
RThe example with the calc did,but when i removed it for the .exe it didn't.
Not sure why the powershell didn't work, it returned this error message;
The term 'xbmc.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the sp
elling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:9
+ xbmc.ps1 <<<<
+ CategoryInfo : ObjectNotFound: (xbmc.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command xbmc.ps1 was not found, but does exist in the current location. Windows PowerShell d
oesn't load commands from the current location by default. If you trust this command, instead type ".\xbmc.ps1". See "ge
t-help about_Command_Precedence" for more details.
ASKER
just realised its a clean PC build so had powersell restriction enabled, switched it off using "Set-ExecutionPolicy RemoteSigned" and it run fine.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks very much
Thanks for the assisted there, wasn't trying to jump in on good solution you already had!
Steve
Steve
detox1978
I don't deserve points here as I was merely repeating someone else's code. I am quite happy for you to re-open this question and re-assign the points.
I have asked a moderator to assist you.
Thank you.
I don't deserve points here as I was merely repeating someone else's code. I am quite happy for you to re-open this question and re-assign the points.
I have asked a moderator to assist you.
Thank you.
Open in new window