CODE
-----------------------------------------------------------------
-- Name: ServiceRunning.lua
-- Author: Kevin Prestage
-- Required INM version: 3.3
-- Version: 1.0
-- Date: 2008-03-21
-- Description: This script will check the
-- running state of a service.
--
-- Arguments:
-- 1) The name of the service to check
-- 2) "true" or "false". Use true to check if the service IS running.
-- flase will verify that the service is NOT running.
----------------------------------------------------------------------------------------------------------
--Start a timer so we can monitor the performance of this script.
Timer = TLuaTimer();
Timer:Start();
result = ""; --this will store our result text
b = true; --this is the status of the script.
--set the name of the file containing safe processes.
sn = GetArgument(0);
state = GetArgument(1);
foundit = false;
--Query WMI for a list of all processes running on the machine.
Query = TLuaWMIQuery();
b = Query:Execute("Select * from Win32_Service");
--if the query failed, set the result.
if (b == false) then
result = "An error occurred querying WMI. " .. Query:GetErrorDescription();
else
while (Query:NextInstance()) do
--get the process name
bOk,exeName = Query:GetProperty("Name",exeName);
exeName = string.lower(exeName);
--print (exeName);
--if the service is a match and it SHOULD be running, set foundit = true
if exeName == string.lower(sn) then
foundit = true;
end
end
if foundit == true then
if state == "true" then
b = true;
result = "The service is running!";
else
b = false;
result = "The service is running and it SHOULD NOT BE";
end
else
if state == "false" then
b = true;
reuslt = "The service is NOT running";
else
b = false;
result = "The service is NOT running and it SHOULD BE.";
end
end
end
--Store the execution time of the script.
mil = Timer:Stop();
StoreStatisticalData(0,mil,0,"Milliseconds");
SetExitStatus(result,b);
-- Name: ServiceRunning.lua
-- Author: Kevin Prestage
-- Required INM version: 3.3
-- Version: 1.0
-- Date: 2008-03-21
-- Description: This script will check the
-- running state of a service.
--
-- Arguments:
-- 1) The name of the service to check
-- 2) "true" or "false". Use true to check if the service IS running.
-- flase will verify that the service is NOT running.
----------------------------------------------------------------------------------------------------------
--Start a timer so we can monitor the performance of this script.
Timer = TLuaTimer();
Timer:Start();
result = ""; --this will store our result text
b = true; --this is the status of the script.
--set the name of the file containing safe processes.
sn = GetArgument(0);
state = GetArgument(1);
foundit = false;
--Query WMI for a list of all processes running on the machine.
Query = TLuaWMIQuery();
b = Query:Execute("Select * from Win32_Service");
--if the query failed, set the result.
if (b == false) then
result = "An error occurred querying WMI. " .. Query:GetErrorDescription();
else
while (Query:NextInstance()) do
--get the process name
bOk,exeName = Query:GetProperty("Name",exeName);
exeName = string.lower(exeName);
--print (exeName);
--if the service is a match and it SHOULD be running, set foundit = true
if exeName == string.lower(sn) then
foundit = true;
end
end
if foundit == true then
if state == "true" then
b = true;
result = "The service is running!";
else
b = false;
result = "The service is running and it SHOULD NOT BE";
end
else
if state == "false" then
b = true;
reuslt = "The service is NOT running";
else
b = false;
result = "The service is NOT running and it SHOULD BE.";
end
end
end
--Store the execution time of the script.
mil = Timer:Stop();
StoreStatisticalData(0,mil,0,"Milliseconds");
SetExitStatus(result,b);