source: nscp/trunk/modules/SysTray/SysTray.cpp @ edbbfbb

Last change on this file since edbbfbb was 99bb030, checked in by Michael Medin <michael@…>, 7 years ago

* empty log message *

  • Property mode set to 100644
File size: 2.3 KB
Line 
1// SysTray.cpp : Defines the entry point for the DLL application.
2//
3
4#include "stdafx.h"
5#include "SysTray.h"
6#include "TrayIcon.h"
7#include <ServiceCmd.h>
8#include <config.h>
9
10SysTray gSysTray;
11
12BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
13{
14        NSCModuleWrapper::wrapDllMain(hModule, ul_reason_for_call);
15    return TRUE;
16}
17
18SysTray::SysTray() {}
19SysTray::~SysTray() {}
20bool SysTray::loadModule() {
21        try {
22                if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) {
23                        NSC_LOG_ERROR("SysTray is not installed (or it cannot interact with the desktop) SysTray wont be loaded. Run " SZAPPNAME " SysTray install ti change this.");
24                        return true;
25                }
26        } catch (serviceControll::SCException e) {
27                NSC_LOG_ERROR("SysTray is not installed (or it cannot interact with the desktop) SysTray wont be loaded. Run " SZAPPNAME " SysTray install ti change this.");
28                return true;
29        }
30        icon.createThread();
31        return true;
32}
33bool SysTray::unloadModule() {
34        if (!icon.exitThread(20000)) {
35                std::cout << "MAJOR ERROR: Could not unload thread..." << std::endl;
36                NSC_LOG_ERROR("Could not exit the thread, memory leak and potential corruption may be the result...");
37                return false;
38        }
39        return true;
40}
41
42int SysTray::commandLineExec(const char* command,const unsigned int argLen,char** args) {
43        if (stricmp(command, "install") == 0) {
44                try {
45                        serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS);
46                        NSC_LOG_MESSAGE(MODULE_NAME " is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set.");
47                } catch (const serviceControll::SCException& e) {
48                        NSC_LOG_ERROR("Could not modify service: " + e.error_);
49                        return -1;
50                }
51        } else if (stricmp(command, "uninstall") == 0) {
52                try {
53                        serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS);
54                        NSC_LOG_MESSAGE(MODULE_NAME " is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset.");
55                } catch (const serviceControll::SCException& e) {
56                        NSC_LOG_ERROR("Could not modify service: " + e.error_);
57                        return -1;
58                }
59        }
60        return 0;
61}
62
63bool SysTray::hasCommandHandler() {
64        return false;
65}
66bool SysTray::hasMessageHandler() {
67        return false;
68}
69
70NSC_WRAPPERS_MAIN_DEF(gSysTray);
71NSC_WRAPPERS_IGNORE_MSG_DEF();
72NSC_WRAPPERS_IGNORE_CMD_DEF();
73NSC_WRAPPERS_CLI_DEF(gSysTray);
74
Note: See TracBrowser for help on using the repository browser.