Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script for checking if a service is running, and starting it, if it is not

Status
Not open for further replies.

tumichaelf

IS-IT--Management
May 17, 2011
33
US
Hello,

Thanks-in-advance first off for reading this.

I need a windows script, that will run on Windows Server 2008 R2 Standard Edition, that will check if 2 processes (vpxd.exe and tomcat6.ext) are running. If they are not running, I need the script to start either one (or both).

I have 0 windows scripting knowledge, so any help would be greatly appreciated, as everything I am finding online seems to be overkill for this.

Thanks again,

Michael
 
After further investigation and research, I created the following

Code:
for /F "tokens=3 delims=: " %%H in ('sc query "vpxd" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vpxd"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vctomcat" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vctomcat"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vimPBSM" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vimPBSM"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vimQueryService" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vimQueryService"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "VMTools" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "VMTools"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "VMUSBArbService" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "VMUSBArbService"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vmware-autodeploy-waiter" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vmware-autodeploy-waiter"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vmware-converter-agent" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vmware-converter-agent"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vmware-converter-server" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vmware-converter-server"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vmware-converter-worker" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vmware-converter-worker"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vmware-ufad-vci" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vmware-ufad-vci"
  )
)

for /F "tokens=3 delims=: " %%H in ('sc query "vspherewebclientsvc" ^| findstr "STATE"') do (
  if /I "%%H" NEQ "RUNNING" (
   net start "vspherewebclientsvc"
  )
)

but if the first for statement is not met, it does not continue. Without creating 1 script for each service, any ideas on how to get this working as a whole.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top