mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-15 18:04:56 +02:00
2008-12-03 Esteban Sanchez <estebans@artica.es>
* pandora.[cc,h]: Function is_enabled() was moved here to be accesible. * pandora_windows_service.cc: Removed is_enabled() private function. * windows_service.cc: Service is now interactive, so it can open interactive processes in the watchdog mode of proc modules. * modules/pandora_module_factory.cc: Added "module_watchdog" and "module_start_command" tokens to service and process modules. Style correction. * modules/pandora_module_proc.[cc,h]: Added watchdog mode to run proccess when they die. It's done by setting a start command to recover it. * modules/pandora_module_service.[cc,h]: Added watchdog mode to start a service when it's stopped. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1277 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
3fe199fbe7
commit
dfb6467cb5
@ -1,3 +1,24 @@
|
|||||||
|
2008-12-03 Esteban Sanchez <estebans@artica.es>
|
||||||
|
|
||||||
|
* pandora.[cc,h]: Function is_enabled() was moved here to be
|
||||||
|
accesible.
|
||||||
|
|
||||||
|
* pandora_windows_service.cc: Removed is_enabled() private function.
|
||||||
|
|
||||||
|
* windows_service.cc: Service is now interactive, so it can open
|
||||||
|
interactive processes in the watchdog mode of proc modules.
|
||||||
|
|
||||||
|
* modules/pandora_module_factory.cc: Added "module_watchdog" and
|
||||||
|
"module_start_command" tokens to service and process modules. Style
|
||||||
|
correction.
|
||||||
|
|
||||||
|
* modules/pandora_module_proc.[cc,h]: Added watchdog mode to run
|
||||||
|
proccess when they die. It's done by setting a start command to
|
||||||
|
recover it.
|
||||||
|
|
||||||
|
* modules/pandora_module_service.[cc,h]: Added watchdog mode to start
|
||||||
|
a service when it's stopped.
|
||||||
|
|
||||||
2008-12-01 Ramon Novoa <rnovoa@artica.es>
|
2008-12-01 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* windows/pandora_wmi.cc,
|
* windows/pandora_wmi.cc,
|
||||||
|
@ -102,8 +102,7 @@ namespace Pandora_Modules {
|
|||||||
*/
|
*/
|
||||||
class Interval_Not_Fulfilled : public Pandora_Modules::Module_Exception { };
|
class Interval_Not_Fulfilled : public Pandora_Modules::Module_Exception { };
|
||||||
|
|
||||||
/**
|
/**
* Pandora module super-class.
|
||||||
* Pandora module super-class.
|
|
||||||
*
|
*
|
||||||
* Every defined module must inherit of this class.
|
* Every defined module must inherit of this class.
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,8 @@ using namespace Pandora_Strutils;
|
|||||||
#define TOKEN_EVENTCODE ("module_eventcode ")
|
#define TOKEN_EVENTCODE ("module_eventcode ")
|
||||||
#define TOKEN_PATTERN ("module_pattern ")
|
#define TOKEN_PATTERN ("module_pattern ")
|
||||||
#define TOKEN_ASYNC ("module_async")
|
#define TOKEN_ASYNC ("module_async")
|
||||||
|
#define TOKEN_WATCHDOG ("module_watchdog ")
|
||||||
|
#define TOKEN_START_COMMAND ("module_start_command ")
|
||||||
|
|
||||||
string
|
string
|
||||||
parseLine (string line, string token) {
|
parseLine (string line, string token) {
|
||||||
@ -91,6 +93,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
string module_odbc_query, module_dsn, module_freememory;
|
string module_odbc_query, module_dsn, module_freememory;
|
||||||
string module_logevent, module_source, module_eventtype, module_eventcode;
|
string module_logevent, module_source, module_eventtype, module_eventcode;
|
||||||
string module_pattern, module_async;
|
string module_pattern, module_async;
|
||||||
|
string module_watchdog, module_start_command;
|
||||||
Pandora_Module *module;
|
Pandora_Module *module;
|
||||||
bool numeric;
|
bool numeric;
|
||||||
Module_Type type;
|
Module_Type type;
|
||||||
@ -112,6 +115,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
module_eventtype = "";
|
module_eventtype = "";
|
||||||
module_eventcode = "";
|
module_eventcode = "";
|
||||||
module_pattern = "";
|
module_pattern = "";
|
||||||
|
module_async = "";
|
||||||
|
module_watchdog = "";
|
||||||
|
module_start_command = "";
|
||||||
|
|
||||||
stringtok (tokens, definition, "\n");
|
stringtok (tokens, definition, "\n");
|
||||||
|
|
||||||
@ -182,6 +188,12 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
if (module_async == "") {
|
if (module_async == "") {
|
||||||
module_async = parseLine (line, TOKEN_ASYNC);
|
module_async = parseLine (line, TOKEN_ASYNC);
|
||||||
}
|
}
|
||||||
|
if (module_start_command == "") {
|
||||||
|
module_start_command = parseLine (line, TOKEN_START_COMMAND);
|
||||||
|
}
|
||||||
|
if (module_watchdog == "") {
|
||||||
|
module_watchdog = parseLine (line, TOKEN_WATCHDOG);
|
||||||
|
}
|
||||||
|
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
@ -193,9 +205,35 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
} else if (module_proc != "") {
|
} else if (module_proc != "") {
|
||||||
module = new Pandora_Module_Proc (module_name,
|
module = new Pandora_Module_Proc (module_name,
|
||||||
module_proc);
|
module_proc);
|
||||||
|
if (module_watchdog != "") {
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
|
enabled = is_enabled (module_watchdog);
|
||||||
|
if (enabled) {
|
||||||
|
if (module_start_command == "") {
|
||||||
|
pandoraLog ("Module \"%s\" is marked to be watchdog but no recover command was set. "
|
||||||
|
"Please add a new token 'module_start_command c:\\command_to_recover.exe'",
|
||||||
|
module_name.c_str ());
|
||||||
|
delete module;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pandora_Module_Proc *module_proc;
|
||||||
|
|
||||||
|
module_proc = (Pandora_Module_Proc *) module;
|
||||||
|
module_proc->setWatchdog (true);
|
||||||
|
module_proc->setStartCommand (module_start_command);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (module_service != "") {
|
} else if (module_service != "") {
|
||||||
module = new Pandora_Module_Service (module_name,
|
module = new Pandora_Module_Service (module_name,
|
||||||
module_service);
|
module_service);
|
||||||
|
if (module_watchdog != "") {
|
||||||
|
Pandora_Module_Service *module_service;
|
||||||
|
|
||||||
|
module_service = (Pandora_Module_Service *) module;
|
||||||
|
module_service->setWatchdog (is_enabled (module_watchdog));
|
||||||
|
}
|
||||||
} else if (module_freedisk != "") {
|
} else if (module_freedisk != "") {
|
||||||
module = new Pandora_Module_Freedisk (module_name,
|
module = new Pandora_Module_Freedisk (module_name,
|
||||||
module_freedisk);
|
module_freedisk);
|
||||||
@ -297,5 +335,6 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||||||
module_name.c_str ());
|
module_name.c_str ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,9 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
|
|||||||
this->process_name.begin (), (int (*) (int)) tolower);
|
this->process_name.begin (), (int (*) (int)) tolower);
|
||||||
|
|
||||||
this->setKind (module_proc_str);
|
this->setKind (module_proc_str);
|
||||||
|
|
||||||
|
this->watchdog = false;
|
||||||
|
this->start_command = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
@ -53,6 +56,26 @@ Pandora_Module_Proc::getProcessName () const {
|
|||||||
return this->process_name;
|
return this->process_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Pandora_Module_Proc::isWatchdog () const {
|
||||||
|
return this->watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
Pandora_Module_Proc::getStartCommand () const {
|
||||||
|
return this->start_command;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Pandora_Module_Proc::setWatchdog (bool watchdog) {
|
||||||
|
this->watchdog = watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Pandora_Module_Proc::setStartCommand (string command) {
|
||||||
|
this->start_command = command;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
async_run (Pandora_Module_Proc *module) {
|
async_run (Pandora_Module_Proc *module) {
|
||||||
HANDLE *processes = NULL;
|
HANDLE *processes = NULL;
|
||||||
@ -72,6 +95,9 @@ async_run (Pandora_Module_Proc *module) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
processes = getProcessHandles (module->getProcessName ());
|
processes = getProcessHandles (module->getProcessName ());
|
||||||
if (processes == NULL) {
|
if (processes == NULL) {
|
||||||
|
if (module->isWatchdog ()) {
|
||||||
|
Pandora_Wmi::runProgram (module->getStartCommand ());
|
||||||
|
}
|
||||||
Sleep (2000);
|
Sleep (2000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -106,6 +132,10 @@ async_run (Pandora_Module_Proc *module) {
|
|||||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res == 0 && module->isWatchdog ()) {
|
||||||
|
Pandora_Wmi::runProgram (module->getStartCommand ());
|
||||||
|
}
|
||||||
|
|
||||||
/* Free handles */
|
/* Free handles */
|
||||||
for (i = 0; i < nprocess; i++)
|
for (i = 0; i < nprocess; i++)
|
||||||
CloseHandle (processes[i]);
|
CloseHandle (processes[i]);
|
||||||
|
@ -31,10 +31,17 @@ namespace Pandora_Modules {
|
|||||||
private:
|
private:
|
||||||
string process_name;
|
string process_name;
|
||||||
HANDLE thread;
|
HANDLE thread;
|
||||||
|
bool watchdog;
|
||||||
|
string start_command;
|
||||||
public:
|
public:
|
||||||
Pandora_Module_Proc (string name, string process_name);
|
Pandora_Module_Proc (string name, string process_name);
|
||||||
|
|
||||||
string getProcessName () const;
|
string getProcessName () const;
|
||||||
|
string getStartCommand () const;
|
||||||
|
bool isWatchdog () const;
|
||||||
|
|
||||||
|
void setWatchdog (bool watchdog);
|
||||||
|
void setStartCommand (string command);
|
||||||
|
|
||||||
void run ();
|
void run ();
|
||||||
};
|
};
|
||||||
|
@ -47,6 +47,7 @@ Pandora_Module_Service::Pandora_Module_Service (string name, string service_name
|
|||||||
|
|
||||||
this->setKind (module_service_str);
|
this->setKind (module_service_str);
|
||||||
this->thread = 0;
|
this->thread = 0;
|
||||||
|
this->watchdog = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
string
|
||||||
@ -54,6 +55,17 @@ Pandora_Module_Service::getServiceName () const {
|
|||||||
return this->service_name;
|
return this->service_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Pandora_Module_Service::isWatchdog () const {
|
||||||
|
return this->watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Pandora_Module_Service::setWatchdog (bool watchdog) {
|
||||||
|
this->watchdog = watchdog;
|
||||||
|
}
|
||||||
|
|
||||||
#define BUFFER_SIZE (16384)
|
#define BUFFER_SIZE (16384)
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -107,8 +119,8 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
continue;
|
continue;
|
||||||
event_id = record->EventID & 0x0000ffff;
|
event_id = record->EventID & 0x0000ffff;
|
||||||
|
|
||||||
/* Those numbers are the code for service start/stopping */
|
/* This number is the code for service start/stopping */
|
||||||
if (event_id == 7035 || event_id == 7036) {
|
if (event_id == 7036) {
|
||||||
service_event = true;
|
service_event = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -123,6 +135,10 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
prev_res = str_res;
|
prev_res = str_res;
|
||||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (res == 0 && module->isWatchdog ()) {
|
||||||
|
Pandora_Wmi::startService (module->getServiceName ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CloseHandle (event);
|
CloseHandle (event);
|
||||||
CloseEventLog (event_log);
|
CloseEventLog (event_log);
|
||||||
|
@ -33,11 +33,15 @@ namespace Pandora_Modules {
|
|||||||
private:
|
private:
|
||||||
string service_name;
|
string service_name;
|
||||||
HANDLE thread;
|
HANDLE thread;
|
||||||
|
bool watchdog;
|
||||||
public:
|
public:
|
||||||
Pandora_Module_Service (string name, string service_name);
|
Pandora_Module_Service (string name, string service_name);
|
||||||
|
|
||||||
void run ();
|
void run ();
|
||||||
string getServiceName () const;
|
string getServiceName () const;
|
||||||
|
bool isWatchdog () const;
|
||||||
|
|
||||||
|
void setWatchdog (bool watchdog);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,3 +272,22 @@ string
|
|||||||
Pandora::getPandoraAgentVersion () {
|
Pandora::getPandoraAgentVersion () {
|
||||||
return pandora_version;
|
return pandora_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Pandora::is_enabled (string value) {
|
||||||
|
static string enabled_values[] = {"enabled", "1", "on", "yes", "si", "sí", "ok", "true", ""};
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (value == "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (enabled_values[i] != "") {
|
||||||
|
if (enabled_values[i] == value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -67,6 +67,7 @@ namespace Pandora {
|
|||||||
void pandoraLog (char *format, ...);
|
void pandoraLog (char *format, ...);
|
||||||
void pandoraFree (void * e);
|
void pandoraFree (void * e);
|
||||||
|
|
||||||
|
bool is_enabled (string value);
|
||||||
/**
|
/**
|
||||||
* Super-class exception.
|
* Super-class exception.
|
||||||
*
|
*
|
||||||
|
@ -38,8 +38,6 @@ using namespace Pandora;
|
|||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
using namespace Pandora_Strutils;
|
using namespace Pandora_Strutils;
|
||||||
|
|
||||||
string enabled_values[] = {"enabled", "1", "on", "yes", "si", "sí", "ok", ""};
|
|
||||||
|
|
||||||
Pandora_Windows_Service::Pandora_Windows_Service ()
|
Pandora_Windows_Service::Pandora_Windows_Service ()
|
||||||
: Windows_Service (NULL, NULL, NULL) {
|
: Windows_Service (NULL, NULL, NULL) {
|
||||||
this->setInitFunction ((void (Windows_Service::*) ())
|
this->setInitFunction ((void (Windows_Service::*) ())
|
||||||
@ -103,23 +101,6 @@ Pandora_Windows_Service::start () {
|
|||||||
this->started = true;
|
this->started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
is_enabled (string value) {
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (value == "") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (enabled_values[i] != "") {
|
|
||||||
if (enabled_values[i] == value) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Pandora_Windows_Service::pandora_init () {
|
Pandora_Windows_Service::pandora_init () {
|
||||||
string conf_file, interval, debug, transfer_interval;
|
string conf_file, interval, debug, transfer_interval;
|
||||||
|
@ -26,15 +26,16 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <winuser.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Pandora_Wmi;
|
using namespace Pandora_Wmi;
|
||||||
|
|
||||||
static LPWSTR
|
static LPWSTR
|
||||||
getWmiStr (LPCWSTR computer) {
|
getWmiStr (LPCWSTR computer) {
|
||||||
static WCHAR wmi_str [256];
|
static WCHAR wmi_str[256];
|
||||||
|
|
||||||
wcscpy (wmi_str, L"winmgmts:{impersonationLevel=impersonate}!\\\\");
|
wcscpy (wmi_str, L"winmgmts:\\\\");
|
||||||
|
|
||||||
if (computer) {
|
if (computer) {
|
||||||
wcsncat (wmi_str, computer, 128);
|
wcsncat (wmi_str, computer, 128);
|
||||||
@ -388,7 +389,9 @@ Pandora_Wmi::getSystemName () {
|
|||||||
* @return The list of events.
|
* @return The list of events.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Pandora_Wmi::getEventList (string source, string type, string code, string pattern, int interval, list<string> &event_list) {
|
Pandora_Wmi::getEventList (string source, string type, string code,
|
||||||
|
string pattern, int interval,
|
||||||
|
list<string> &event_list) {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
CDispPtr wmi_svc, quickfixes;
|
CDispPtr wmi_svc, quickfixes;
|
||||||
char *value = NULL;
|
char *value = NULL;
|
||||||
@ -512,3 +515,120 @@ Pandora_Wmi::convertWMIDate (string wmi_date, SYSTEMTIME *system_time)
|
|||||||
system_time->wMinute = atoi (wmi_date.substr (10, 2).c_str());
|
system_time->wMinute = atoi (wmi_date.substr (10, 2).c_str());
|
||||||
system_time->wSecond = atoi (wmi_date.substr (12, 2).c_str());
|
system_time->wSecond = atoi (wmi_date.substr (12, 2).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a program in a new process.
|
||||||
|
*
|
||||||
|
* @param command Command to run, with parameters
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
Pandora_Wmi::runProgram (string command) {
|
||||||
|
PROCESS_INFORMATION process_info;
|
||||||
|
STARTUPINFO startup_info;
|
||||||
|
bool success;
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
if (command == "")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ZeroMemory (&startup_info, sizeof (startup_info));
|
||||||
|
startup_info.cb = sizeof (startup_info);
|
||||||
|
ZeroMemory (&process_info, sizeof (process_info));
|
||||||
|
|
||||||
|
pandoraDebug ("Start process \"%s\".", command.c_str ());
|
||||||
|
cmd = strdup (command.c_str ());
|
||||||
|
success = CreateProcess (NULL, cmd, NULL, NULL, FALSE, 0,
|
||||||
|
NULL, NULL, &startup_info, &process_info);
|
||||||
|
pandoraFree (cmd);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
pandoraDebug ("The process \"%s\" was started.", command.c_str ());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
pandoraLog ("Could not start process \"%s\". Error %d", command.c_str (),
|
||||||
|
GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a Windows service.
|
||||||
|
*
|
||||||
|
* @param service_name Service internal name to start.
|
||||||
|
*
|
||||||
|
* @retval true If the service started.
|
||||||
|
* @retval false If the service could not start. A log message is created.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
Pandora_Wmi::startService (string service_name) {
|
||||||
|
SC_HANDLE manager, service;
|
||||||
|
bool success;
|
||||||
|
|
||||||
|
manager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
|
if (manager == NULL) {
|
||||||
|
pandoraLog ("Could not access to service \"%s\" to start.",
|
||||||
|
service_name.c_str ());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
service = OpenService (manager, service_name.c_str (), GENERIC_EXECUTE);
|
||||||
|
if (service == NULL) {
|
||||||
|
pandoraLog ("Could not access to service \"%s\" to start.",
|
||||||
|
service_name.c_str ());
|
||||||
|
CloseServiceHandle (manager);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
success = StartService (service, 0, NULL);
|
||||||
|
|
||||||
|
CloseServiceHandle (service);
|
||||||
|
CloseServiceHandle (manager);
|
||||||
|
|
||||||
|
if (! success) {
|
||||||
|
pandoraLog ("Could not start service \"%s\". (Error %d)",
|
||||||
|
service_name.c_str (), GetLastError ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop a Windows service.
|
||||||
|
*
|
||||||
|
* @param service_name Service internal name to stop.
|
||||||
|
*
|
||||||
|
* @retval true If the service started.
|
||||||
|
* @retval false If the service could not stop. A log message is created.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
Pandora_Wmi::stopService (string service_name) {
|
||||||
|
SC_HANDLE manager, service;
|
||||||
|
bool success;
|
||||||
|
|
||||||
|
manager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
|
if (manager == NULL) {
|
||||||
|
pandoraLog ("Could not access to service \"%s\" to stop.",
|
||||||
|
service_name.c_str ());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
service = OpenService (manager, service_name.c_str (), GENERIC_EXECUTE);
|
||||||
|
if (service == NULL) {
|
||||||
|
pandoraLog ("Could not access to service \"%s\" to stop.",
|
||||||
|
service_name.c_str ());
|
||||||
|
CloseServiceHandle (manager);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
success = ControlService (service, SERVICE_CONTROL_STOP, NULL);
|
||||||
|
|
||||||
|
CloseServiceHandle (service);
|
||||||
|
CloseServiceHandle (manager);
|
||||||
|
|
||||||
|
if (! success) {
|
||||||
|
pandoraLog ("Could not stop service \"%s\". (Error %d)",
|
||||||
|
service_name.c_str (), GetLastError ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -47,9 +47,20 @@ namespace Pandora_Wmi {
|
|||||||
string getOSVersion ();
|
string getOSVersion ();
|
||||||
string getOSBuild ();
|
string getOSBuild ();
|
||||||
string getSystemName ();
|
string getSystemName ();
|
||||||
void getEventList (string source, string type, string code, string pattern, int interval, list<string> &event_list);
|
|
||||||
|
void getEventList (string source,
|
||||||
|
string type,
|
||||||
|
string code,
|
||||||
|
string pattern,
|
||||||
|
int interval,
|
||||||
|
list<string> &event_list);
|
||||||
string getTimestampLimit (int interval);
|
string getTimestampLimit (int interval);
|
||||||
void convertWMIDate (string wmi_date, SYSTEMTIME *system_time);
|
void convertWMIDate (string wmi_date,
|
||||||
|
SYSTEMTIME *system_time);
|
||||||
|
|
||||||
|
bool runProgram (string command);
|
||||||
|
bool startService (string service_name);
|
||||||
|
bool stopService (string service_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -206,7 +206,8 @@ Windows_Service::install (LPCTSTR application_binary_path) {
|
|||||||
service_name, /* name of service */
|
service_name, /* name of service */
|
||||||
service_display_name, /* service name to display */
|
service_display_name, /* service name to display */
|
||||||
SERVICE_ALL_ACCESS, /* desired access */
|
SERVICE_ALL_ACCESS, /* desired access */
|
||||||
SERVICE_WIN32_OWN_PROCESS, /* service type */
|
SERVICE_WIN32_OWN_PROCESS |
|
||||||
|
SERVICE_INTERACTIVE_PROCESS, /* service type, interactive */
|
||||||
SERVICE_AUTO_START, /* start type */
|
SERVICE_AUTO_START, /* start type */
|
||||||
SERVICE_ERROR_NORMAL, /* error control type */
|
SERVICE_ERROR_NORMAL, /* error control type */
|
||||||
application_binary_path, /* service's binary */
|
application_binary_path, /* service's binary */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user