How can I tell if a service is running? I tried several of the examples posted but none seem to work correctly. Need to check if "Norton AntiVirus Server" is running. Thanks
Although not elegant and does little else, this will tell you if the service is running...
code:
function servicestate($_service,optional $remotepc) $objects=GetObject("winmgmts:{impersonationLevel=impersonate}!"+$remotepc+"\root\cimv2") if not @error=0 exit @error endif $services=$objects.ExecQuery('Select * from Win32_Service WHERE Name = "$_service"') for each $service in $services $servicestate=$service.state next endfunction
For example: servicestate("Spooler") returns "Running"
Just threw this together so please be understanding if it contains a bug or two, but it did work in my simple test above.
#40804 - 2003-05-2812:15 AMRe: check if a service is running
Howard BullockHoward Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Check out fADSIServiceRun(). This code uses ADSI via COM to work with services. In it is simple code that will show how to get the status of a service.
Howard, I understand the points that you brought up but what I didn't underdstand was the $servicename. Where is that being declared? Above this script? Thanks
#40809 - 2003-05-2812:47 AMRe: check if a service is running
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11625
Loc: CA
Here is a version tailored to what you want to find. Reading and Experimenting will help increase your knowledge as well. When you have time please review the KiXtart manual as well as the FAQ section here on the board. You can also download the HELPFILE from my site (the link is in my signature)
From a DOS prompt on either Windows 2000 or XP : Using KiXtart v4.21