Changeset c0522cd in nscp


Ignore:
Timestamp:
08/24/08 19:23:10 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
bc97cd8
Parents:
846bbe4
Message:

2008-08-16 MickeM

  • *WARNING* THIS IS VERY VERY UNSTABEL (possibly)
  • *WARNING* A lot of new untested code here so dont run in production enviornments :) + Added shared session so system tray can communicate with master + Added new system tray handlig (via TS so FUS should work with it) + Added new option [System] / shared_session=0 (or 1) to enable / disable the new shared memory framework (it is for now disabled by default) If you want to try this remember to change that option but also beware! it is dagerous and not finnished and and also there is as of now no security at all.
Files:
16 added
38 edited

Legend:

Unmodified
Added
Removed
  • AutoBuild.h

    r846bbe4 rc0522cd  
    33// change the FALSE to TRUE for autoincrement of build number 
    44#define INCREMENT_VERSION TRUE 
    5 #define FILEVER        0,3,3,29 
    6 #define PRODUCTVER     0,3,3,29 
    7 #define STRFILEVER     _T("0.3.3.29") 
    8 #define STRPRODUCTVER  _T("0.3.3.29") 
    9 #define STRPRODUCTDATE  _T("2008-07-28") 
     5#define FILEVER        0,3,3,37 
     6#define PRODUCTVER     0,3,3,37 
     7#define STRFILEVER     _T("0.3.3.37") 
     8#define STRPRODUCTVER  _T("0.3.3.37") 
     9#define STRPRODUCTDATE  _T("2008-08-24") 
    1010#endif // AUTOBUILD_H 
  • NSC.dist

    rdff5db9 rc0522cd  
    5454;  the registry will be used instead. 
    5555use_file=1 
     56; 
     57; # USE SHARED MEMORY CHANNELS 
     58;  This is the "new" way for using the system tray based on an IPC framework on top shared memmory channels and events. 
     59;  It is brand new and (probably has bugs) so dont enable this unless for testing! 
     60;  If set to 1 shared channels will be created and system tray icons created and such and such... 
     61;shared_session=0 
     62 
    5663 
    5764[log] 
     
    6269;# LOG FILE 
    6370;  The file to print log statements to 
    64 ;file=NSC.log 
     71;file=nsclient.log 
    6572; 
    6673;# LOG DATE MASK 
    6774;  The format to for the date/time part of the log entry written to file. 
    6875;date_mask=%Y-%m-%d %H:%M:%S 
     76; 
     77;# LOG ROOT FOLDER 
     78;  The root folder to use for logging. 
     79;  exe = the folder where the executable is located 
     80;  local-app-data = local application data (probably a better choice then the old default) 
     81;root_folder=exe 
    6982 
    7083 
  • NSCPlugin.cpp

    rc1d545e rc0522cd  
    4242  ,fGetVersion(NULL) 
    4343  ,fCommandLineExec(NULL) 
     44  ,fShowTray(NULL) 
     45  ,fHideTray(NULL) 
    4446  ,bLoaded_(false) 
    4547{ 
     
    5860  ,fGetVersion(NULL) 
    5961  ,fCommandLineExec(NULL) 
     62  ,fShowTray(NULL) 
     63  ,fHideTray(NULL) 
    6064  ,bLoaded_(false) 
    6165{ 
     
    8993  TCHAR *buffer = new TCHAR[1024]; 
    9094  if (!getName_(buffer, 1023)) { 
    91     throw NSPluginException(file_, _T("Could not get name")); 
     95    return _T("Could not get name"); 
    9296  } 
    9397  std::wstring ret = buffer; 
     
    244248bool NSCPlugin::getName_(TCHAR* buf, unsigned int buflen) { 
    245249  if (fGetName == NULL) 
    246     throw NSPluginException(file_, _T("Critical error (fGetName)")); 
     250    return false;//throw NSPluginException(file_, _T("Critical error (fGetName)")); 
    247251  try { 
    248252    return fGetName(buf, buflen)?true:false; 
    249253  } catch (...) { 
    250     throw NSPluginException(file_, _T("Unhandled exception in getName.")); 
     254    return false; //throw NSPluginException(file_, _T("Unhandled exception in getName.")); 
    251255  } 
    252256} 
     
    260264  } 
    261265} 
     266 
     267void NSCPlugin::showTray() { 
     268  if (fShowTray == NULL) 
     269    throw NSPluginException(file_, _T("Critical error (ShowTray)")); 
     270  try { 
     271    fShowTray(); 
     272  } catch (...) { 
     273    throw NSPluginException(file_, _T("Unhandled exception in ShowTray.")); 
     274  } 
     275} 
     276void NSCPlugin::hideTray() { 
     277  if (fHideTray == NULL) 
     278    throw NSPluginException(file_, _T("Critical error (HideTray)")); 
     279  try { 
     280    fHideTray(); 
     281  } catch (...) { 
     282    throw NSPluginException(file_, _T("Unhandled exception in HideTray.")); 
     283  } 
     284} 
     285 
    262286/** 
    263287 * Load all remote function pointers from the loaded module. 
     
    316340  fGetConfigurationMeta = (lpGetConfigurationMeta)GetProcAddress(hModule_, "NSGetConfigurationMeta"); 
    317341  fCommandLineExec = (lpCommandLineExec)GetProcAddress(hModule_, "NSCommandLineExec"); 
     342 
     343  fShowTray = (lpShowTray)GetProcAddress(hModule_, "ShowIcon"); 
     344  fHideTray = (lpHideTray)GetProcAddress(hModule_, "HideIcon"); 
     345 
    318346} 
    319347 
  • NSCPlugin.h

    r99e4d8f rc0522cd  
    107107  typedef INT (*lpUnLoadModule)(); 
    108108  typedef INT (*lpGetConfigurationMeta)(int, TCHAR*); 
     109  typedef void (*lpShowTray)(); 
     110  typedef void (*lpHideTray)(); 
    109111 
    110112 
     
    121123  lpGetConfigurationMeta fGetConfigurationMeta; 
    122124  lpCommandLineExec fCommandLineExec; 
     125  lpShowTray fShowTray; 
     126  lpHideTray fHideTray; 
    123127 
    124128public: 
     
    139143  std::wstring getCongifurationMeta(); 
    140144  int commandLineExec(const TCHAR* command, const unsigned int argLen, TCHAR **arguments); 
     145  void showTray(); 
     146  void hideTray(); 
     147 
    141148  std::wstring getModule() { 
    142149    if (file_.empty()) 
  • NSClient++-2005.sln

    rda1c7e1 rc0522cd  
    66    Release.AspNetCompiler.Debug = "False" 
    77  EndProjectSection 
    8   ProjectSection(ProjectDependencies) = postProject 
    9     {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {F3401E75-60FB-4A0E-A18C-6505587D5B1A} 
    10     {BA246C01-063A-4548-8957-32D5CC76171B} = {BA246C01-063A-4548-8957-32D5CC76171B} 
    11     {BBFF8362-C626-4838-B0A2-F695D638AD24} = {BBFF8362-C626-4838-B0A2-F695D638AD24} 
    12     {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} = {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45} 
    13     {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} = {05DE66AC-E55C-43B3-849F-7EC695D8B8D0} 
    14     {6F55C9BF-57F6-4A15-A058-C83A52F539EE} = {6F55C9BF-57F6-4A15-A058-C83A52F539EE} 
    15     {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} = {4241C6CF-EC01-4AD9-89B0-B75EBA8A5996} 
    16     {26B84883-BE52-40E6-9BEE-55AD056D5751} = {26B84883-BE52-40E6-9BEE-55AD056D5751} 
    17     {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} = {0BEEC749-0E3E-4FB2-82DA-AC8D4730A129} 
    18     {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} = {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4} 
    19     {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} = {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F} 
    20     {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} = {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D} 
    21     {08D6246D-1B4A-47A3-965D-296DCC54A4E8} = {08D6246D-1B4A-47A3-965D-296DCC54A4E8} 
    22     {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} = {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F} 
    23     {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} = {2FF60AF6-09AA-49AB-B414-2E8FD01655C6} 
    24   EndProjectSection 
    258EndProject 
    269Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SysTray", "modules\SysTray\SysTray-2005.vcproj", "{BBFF8362-C626-4838-B0A2-F695D638AD24}" 
     
    157140  ProjectSection(ProjectDependencies) = postProject 
    158141    {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 
     142    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 
    159143  EndProjectSection 
    160144EndProject 
     
    175159  EndProjectSection 
    176160  ProjectSection(ProjectDependencies) = postProject 
     161    {43718644-173B-42D8-8AD1-E359BFB2BB20} = {43718644-173B-42D8-8AD1-E359BFB2BB20} 
    177162    {2286162D-7571-4735-BAC8-4A8D33A4F42D} = {2286162D-7571-4735-BAC8-4A8D33A4F42D} 
    178163  EndProjectSection 
     
    191176EndProject 
    192177Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckTaskSched", "modules\CheckTaskSched\CheckTaskSched-2005.vcproj", "{F3401E75-60FB-4A0E-A18C-6505587D5B1A}" 
     178  ProjectSection(WebsiteProperties) = preProject 
     179    Debug.AspNetCompiler.Debug = "True" 
     180    Release.AspNetCompiler.Debug = "False" 
     181  EndProjectSection 
     182EndProject 
     183Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "systray_helper", "helpers\systray_helper\systray_helper.vcproj", "{43718644-173B-42D8-8AD1-E359BFB2BB20}" 
    193184  ProjectSection(WebsiteProperties) = preProject 
    194185    Debug.AspNetCompiler.Debug = "True" 
     
    262253    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|Win32.ActiveCfg = Release|Win32 
    263254    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|Win32.Build.0 = Release|Win32 
    264     {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|x64.ActiveCfg = Release|Win32 
     255    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|x64.ActiveCfg = Release|x64 
     256    {2286162D-7571-4735-BAC8-4A8D33A4F42D}.Release|x64.Build.0 = Release|x64 
    265257    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Any CPU.ActiveCfg = Debug|x64 
    266258    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    300292    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|Win32.ActiveCfg = Release|Win32 
    301293    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|Win32.Build.0 = Release|Win32 
    302     {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|x64.ActiveCfg = Release|Win32 
     294    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|x64.ActiveCfg = Release|x64 
     295    {BBFF8362-C626-4838-B0A2-F695D638AD24}.Release|x64.Build.0 = Release|x64 
    303296    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Any CPU.ActiveCfg = Debug|x64 
    304297    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    338331    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|Win32.ActiveCfg = Release|Win32 
    339332    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|Win32.Build.0 = Release|Win32 
    340     {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|x64.ActiveCfg = Release|Win32 
     333    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|x64.ActiveCfg = Release|x64 
     334    {62B685D7-3A2E-4F3E-B2B8-B17F20C0217F}.Release|x64.Build.0 = Release|x64 
    341335    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Any CPU.ActiveCfg = Debug|x64 
    342336    {BA246C01-063A-4548-8957-32D5CC76171B}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    376370    {BA246C01-063A-4548-8957-32D5CC76171B}.Release|Win32.ActiveCfg = Release|Win32 
    377371    {BA246C01-063A-4548-8957-32D5CC76171B}.Release|Win32.Build.0 = Release|Win32 
    378     {BA246C01-063A-4548-8957-32D5CC76171B}.Release|x64.ActiveCfg = Release|Win32 
     372    {BA246C01-063A-4548-8957-32D5CC76171B}.Release|x64.ActiveCfg = Release|x64 
     373    {BA246C01-063A-4548-8957-32D5CC76171B}.Release|x64.Build.0 = Release|x64 
    379374    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Any CPU.ActiveCfg = Debug|x64 
    380375    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    414409    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|Win32.ActiveCfg = Release|Win32 
    415410    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|Win32.Build.0 = Release|Win32 
    416     {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|x64.ActiveCfg = Release|Win32 
     411    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|x64.ActiveCfg = Release|x64 
     412    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release|x64.Build.0 = Release|x64 
    417413    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Any CPU.ActiveCfg = Debug|x64 
    418414    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    452448    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|Win32.ActiveCfg = Release|Win32 
    453449    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|Win32.Build.0 = Release|Win32 
    454     {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|x64.ActiveCfg = Release|Win32 
     450    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|x64.ActiveCfg = Release|x64 
     451    {2FF60AF6-09AA-49AB-B414-2E8FD01655C6}.Release|x64.Build.0 = Release|x64 
    455452    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Any CPU.ActiveCfg = Debug|x64 
    456453    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    490487    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|Win32.ActiveCfg = Release|Win32 
    491488    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|Win32.Build.0 = Release|Win32 
    492     {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|x64.ActiveCfg = Release|Win32 
     489    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|x64.ActiveCfg = Release|x64 
     490    {08D6246D-1B4A-47A3-965D-296DCC54A4E8}.Release|x64.Build.0 = Release|x64 
    493491    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Any CPU.ActiveCfg = Debug|x64 
    494492    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    528526    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|Win32.ActiveCfg = Release|Win32 
    529527    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|Win32.Build.0 = Release|Win32 
    530     {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|x64.ActiveCfg = Release|Win32 
     528    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|x64.ActiveCfg = Release|x64 
     529    {2FCAF54B-AAD3-4F59-895A-8F9CEAFDC65D}.Release|x64.Build.0 = Release|x64 
    531530    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Any CPU.ActiveCfg = Debug|x64 
    532531    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    566565    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|Win32.ActiveCfg = Release|Win32 
    567566    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|Win32.Build.0 = Release|Win32 
    568     {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|x64.ActiveCfg = Release|Win32 
     567    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|x64.ActiveCfg = Release|x64 
     568    {8F1C3E39-D6C6-4414-AAD2-FE03C9A8655F}.Release|x64.Build.0 = Release|x64 
    569569    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Any CPU.ActiveCfg = Debug|x64 
    570570    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    604604    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|Win32.ActiveCfg = Release|Win32 
    605605    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|Win32.Build.0 = Release|Win32 
    606     {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|x64.ActiveCfg = Release|Win32 
     606    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|x64.ActiveCfg = Release|x64 
     607    {05DE66AC-E55C-43B3-849F-7EC695D8B8D0}.Release|x64.Build.0 = Release|x64 
    607608    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Any CPU.ActiveCfg = Debug|x64 
    608609    {626EB00E-A4D2-4B02-9BF4-4C655CA2B7E4}.Debug|Itanium.ActiveCfg = Debug|x64 
     
    10391040    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|Win32.Build.0 = Release|Win32 
    10401041    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|x64.ActiveCfg = Release|x64 
    1041     {D96F7075-F6CD-4921-B5D8-8488E2D24BDB}.Release|x64.Build.0 = Release|x64 
    10421042    {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Debug|Any CPU.ActiveCfg = Debug|Win32 
    10431043    {19BF0AD8-0013-46C7-9E91-F60FE3B0A63D}.Debug|Itanium.ActiveCfg = Debug|Win32 
     
    11141114    {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Release|x64.ActiveCfg = Release|x64 
    11151115    {F3401E75-60FB-4A0E-A18C-6505587D5B1A}.Release|x64.Build.0 = Release|x64 
     1116    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Any CPU.ActiveCfg = Debug|Win32 
     1117    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Itanium.ActiveCfg = Debug|Win32 
     1118    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 
     1119    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Mixed Platforms.Build.0 = Debug|Win32 
     1120    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.ActiveCfg = Debug|Win32 
     1121    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|Win32.Build.0 = Debug|Win32 
     1122    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.ActiveCfg = Debug|x64 
     1123    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug|x64.Build.0 = Debug|x64 
     1124    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Any CPU.ActiveCfg = Debug|Win32 
     1125    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Itanium.ActiveCfg = Debug|Win32 
     1126    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Mixed Platforms.ActiveCfg = Debug|Win32 
     1127    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Mixed Platforms.Build.0 = Debug|Win32 
     1128    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Win32.ActiveCfg = Debug|Win32 
     1129    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|Win32.Build.0 = Debug|Win32 
     1130    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Debug-MemCheck|x64.ActiveCfg = Debug|Win32 
     1131    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Any CPU.ActiveCfg = Debug|Win32 
     1132    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Itanium.ActiveCfg = Debug|Win32 
     1133    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Mixed Platforms.ActiveCfg = Debug|Win32 
     1134    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Mixed Platforms.Build.0 = Debug|Win32 
     1135    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Win32.ActiveCfg = Debug|Win32 
     1136    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|Win32.Build.0 = Debug|Win32 
     1137    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Distribution|x64.ActiveCfg = Debug|Win32 
     1138    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Any CPU.ActiveCfg = Release|Win32 
     1139    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Itanium.ActiveCfg = Release|Win32 
     1140    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Mixed Platforms.ActiveCfg = Release|Win32 
     1141    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Mixed Platforms.Build.0 = Release|Win32 
     1142    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Win32.ActiveCfg = Nightly|Win32 
     1143    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|Win32.Build.0 = Nightly|Win32 
     1144    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|x64.ActiveCfg = Nightly|x64 
     1145    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Nightly|x64.Build.0 = Nightly|x64 
     1146    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Any CPU.ActiveCfg = Release|Win32 
     1147    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Itanium.ActiveCfg = Release|Win32 
     1148    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Mixed Platforms.ActiveCfg = Release|Win32 
     1149    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Mixed Platforms.Build.0 = Release|Win32 
     1150    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Win32.ActiveCfg = Release|Win32 
     1151    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|Win32.Build.0 = Release|Win32 
     1152    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|x64.ActiveCfg = Release|x64 
     1153    {43718644-173B-42D8-8AD1-E359BFB2BB20}.Release|x64.Build.0 = Release|x64 
    11161154  EndGlobalSection 
    11171155  GlobalSection(SolutionProperties) = preSolution 
     
    11351173    {F3401E75-60FB-4A0E-A18C-6505587D5B1A} = {9757464B-C125-4307-A84A-F4181AE6A081} 
    11361174    {0E2B21D9-F432-4127-8E92-7716B1072510} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    1137     {A3CF4E23-1D1B-4D93-A16A-48C52D118560} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    11381175    {6206F046-3D36-4258-BB03-3291A7070117} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
    11391176    {D96F7075-F6CD-4921-B5D8-8488E2D24BDB} = {9A087442-7BB2-4CF0-9F58-5D1BC3C32CD2} 
  • NSClient++-2005.vcproj

    r367bf20 rc0522cd  
    3838      <Tool 
    3939        Name="VCCustomBuildTool" 
    40         CommandLine="" 
     40        CommandLine="&#x0D;&#x0A;" 
    4141        Outputs="$(InputDir)\$(OutDir)\msvcp71.dll" 
    4242      /> 
     
    8585      <Tool 
    8686        Name="VCLinkerTool" 
    87         AdditionalDependencies="kernel32.lib user32.lib advapi32.lib ws2_32.lib" 
     87        AdditionalDependencies="kernel32.lib user32.lib advapi32.lib ws2_32.lib Userenv.lib" 
    8888        OutputFile=".\Release/NSClient++.exe" 
    8989        LinkIncremental="1" 
     
    139139      <Tool 
    140140        Name="VCCustomBuildTool" 
    141         CommandLine="echo Copying dependency DLLs&#x0D;&#x0A;cmd /c &quot;copy $(InputDir)\dist_dll\*.* $(InputDir)\$(OutDir)\&quot;&#x0D;&#x0A;" 
     141        CommandLine="&#x0D;&#x0A;" 
    142142        Outputs="$(InputDir)\$(OutDir)\msvcp71.dll" 
    143143      /> 
     
    187187      <Tool 
    188188        Name="VCLinkerTool" 
    189         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Pdh.lib" 
     189        AdditionalDependencies="kernel32.lib user32.lib advapi32.lib ws2_32.lib Userenv.lib" 
    190190        OutputFile=".\Release/NSClient++.exe" 
    191191        LinkIncremental="1" 
     
    283283      <Tool 
    284284        Name="VCLinkerTool" 
    285         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 
     285        AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 
    286286        OutputFile=".\Debug/NSClient++.exe" 
    287287        LinkIncremental="1" 
     
    378378      <Tool 
    379379        Name="VCLinkerTool" 
    380         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 
     380        AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 
    381381        OutputFile=".\Debug/NSClient++.exe" 
    382382        LinkIncremental="1" 
     
    669669      <Tool 
    670670        Name="VCLinkerTool" 
    671         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 
     671        AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 
    672672        LinkIncremental="1" 
    673673        SuppressStartupBanner="true" 
     
    757757      <Tool 
    758758        Name="VCLinkerTool" 
    759         AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib" 
     759        AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib Userenv.lib" 
    760760        LinkIncremental="1" 
    761761        SuppressStartupBanner="true" 
     
    23772377      </File> 
    23782378      <File 
     2379        RelativePath=".\include\event_handler.hpp" 
     2380        > 
     2381      </File> 
     2382      <File 
    23792383        RelativePath=".\include\INISettings.h" 
    23802384        > 
     
    24012405      </File> 
    24022406      <File 
     2407        RelativePath=".\include\nsclient_session.hpp" 
     2408        > 
     2409      </File> 
     2410      <File 
    24032411        RelativePath=".\NSCPlugin.h" 
    24042412        > 
     
    24172425      </File> 
    24182426      <File 
     2427        RelativePath=".\include\remote_processes.hpp" 
     2428        > 
     2429      </File> 
     2430      <File 
    24192431        RelativePath=".\include\ServiceCmd.h" 
    24202432        > 
     
    24252437      </File> 
    24262438      <File 
     2439        RelativePath=".\include\shared_memory.hpp" 
     2440        > 
     2441      </File> 
     2442      <File 
    24272443        RelativePath=".\include\Singleton.h" 
    24282444        > 
     
    24422458      <File 
    24432459        RelativePath=".\include\thread.h" 
     2460        > 
     2461      </File> 
     2462      <File 
     2463        RelativePath=".\tray_manager.hpp" 
    24442464        > 
    24452465      </File> 
  • NSClient++.cpp

    r846bbe4 rc0522cd  
    1 ////////////////////////////////////////////////////////////////////////// 
     1/////////////////////////////////////////////////////////////////////////// 
    22// NSClient++ Base Service 
    33//  
     
    2222#include <config.h> 
    2323#include <msvc_wrappers.h> 
    24  
     24#include <Userenv.h> 
     25#include <remote_processes.hpp> 
     26#include <Lmcons.h> 
    2527 
    2628NSClient mainClient;  // Global core instance. 
    2729bool g_bConsoleLog = false; 
     30 
     31 
     32class tray_starter { 
     33  struct start_block { 
     34    std::wstring cmd; 
     35    std::wstring cmd_line; 
     36    DWORD sessionId; 
     37  }; 
     38 
     39public: 
     40  static LPVOID init(DWORD dwSessionId, std::wstring exe, std::wstring cmdline) { 
     41    start_block *sb = new start_block; 
     42    sb->cmd = exe; 
     43    sb->cmd_line = cmdline; 
     44    sb->sessionId = dwSessionId; 
     45    return sb; 
     46  } 
     47  DWORD threadProc(LPVOID lpParameter) { 
     48    start_block* param = static_cast<start_block*>(lpParameter); 
     49    DWORD dwSessionId = param->sessionId; 
     50    std::wstring cmd = param->cmd; 
     51    std::wstring cmdline = param->cmd_line; 
     52    delete param; 
     53    for (int i=0;i<10;i++) { 
     54      Sleep(1000); 
     55      if (startTrayHelper(dwSessionId, cmd, cmdline, false)) 
     56        break; 
     57    } 
     58    return 0; 
     59  } 
     60 
     61  static bool start(DWORD dwSessionId) { 
     62    std::wstring program = mainClient.getBasePath() +  _T("\\") + Settings::getInstance()->getString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_SYSTRAY_EXE, NSCLIENT_SETTINGS_SYSTRAY_EXE_DEFAULT); 
     63    std::wstring cmdln = _T("\"") + program + _T("\" -channel __") + strEx::itos(dwSessionId) + _T("__"); 
     64    return tray_starter::startTrayHelper(dwSessionId, program, cmdln); 
     65  } 
     66 
     67  static bool startTrayHelper(DWORD dwSessionId, std::wstring exe, std::wstring cmdline, bool startThread = true) { 
     68    HANDLE hToken = NULL; 
     69    if (!remote_processes::GetSessionUserToken(dwSessionId, &hToken)) { 
     70      LOG_ERROR_STD(_T("Failed to query user token: ") + error::lookup::last_error()); 
     71      return false; 
     72    } else { 
     73      STARTUPINFO          StartUPInfo; 
     74      PROCESS_INFORMATION  ProcessInfo; 
     75 
     76      ZeroMemory(&StartUPInfo,sizeof(STARTUPINFO)); 
     77      ZeroMemory(&ProcessInfo,sizeof(PROCESS_INFORMATION)); 
     78      StartUPInfo.wShowWindow = SW_HIDE; 
     79      StartUPInfo.lpDesktop = L"Winsta0\\Default"; 
     80      StartUPInfo.cb = sizeof(STARTUPINFO); 
     81 
     82      wchar_t *buffer = new wchar_t[cmdline.size()+10]; 
     83      wcscpy(buffer, cmdline.c_str()); 
     84      LOG_MESSAGE_STD(_T("Running: ") + exe); 
     85      LOG_MESSAGE_STD(_T("Running: ") + cmdline); 
     86 
     87      LPVOID pEnv =NULL; 
     88      DWORD dwCreationFlags = CREATE_NO_WINDOW; //0; //DETACHED_PROCESS 
     89 
     90      if(CreateEnvironmentBlock(&pEnv,hToken,TRUE)) { 
     91        dwCreationFlags|=CREATE_UNICODE_ENVIRONMENT; 
     92      } else { 
     93        LOG_ERROR_STD(_T("Failed to create enviornment: ") + error::lookup::last_error()); 
     94        pEnv=NULL; 
     95      } 
     96      /* 
     97      LOG_ERROR_STD(_T("Impersonating user: ")); 
     98      if (!ImpersonateLoggedOnUser(hToken)) { 
     99        LOG_ERROR_STD(_T("Failed to impersonate the user: ") + error::lookup::last_error()); 
     100      } 
     101 
     102      wchar_t pszUname[UNLEN + 1]; 
     103      ZeroMemory(pszUname,sizeof(pszUname)); 
     104      DWORD dwSize = UNLEN; 
     105      if (!GetUserName(pszUname,&dwSize)) { 
     106        DWORD dwErr = GetLastError(); 
     107        if (!RevertToSelf()) 
     108          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     109        LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 
     110        return false; 
     111      } 
     112       
     113 
     114      PROFILEINFO info; 
     115      info.dwSize = sizeof(PROFILEINFO); 
     116      info.lpUserName = pszUname; 
     117      if (!LoadUserProfile(hToken, &info)) { 
     118        DWORD dwErr = GetLastError(); 
     119        if (!RevertToSelf()) 
     120          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     121        LOG_ERROR_STD(_T("Failed to get username: ") + error::format::from_system(dwErr)); 
     122        return false; 
     123      } 
     124      */ 
     125      if (!CreateProcessAsUser(hToken, exe.c_str(), buffer, NULL, NULL, FALSE, dwCreationFlags, pEnv, NULL, &StartUPInfo, &ProcessInfo)) { 
     126        DWORD dwErr = GetLastError(); 
     127        delete [] buffer; 
     128        /* 
     129        if (!RevertToSelf()) { 
     130          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     131        } 
     132        */ 
     133        if (startThread && dwErr == ERROR_PIPE_NOT_CONNECTED) { 
     134          LOG_MESSAGE(_T("Failed to start trayhelper: starting a background thread to do it instead...")); 
     135          Thread<tray_starter> *pThread = new Thread<tray_starter>(_T("tray-starter-thread")); 
     136          pThread->createThread(tray_starter::init(dwSessionId, exe, cmdline)); 
     137          return false; 
     138        } else if (dwErr == ERROR_PIPE_NOT_CONNECTED) { 
     139          LOG_ERROR_STD(_T("Thread failed to start trayhelper (will try again): ") + error::format::from_system(dwErr)); 
     140          return false; 
     141        } else { 
     142          LOG_ERROR_STD(_T("Failed to start trayhelper: ") + error::format::from_system(dwErr)); 
     143          return true; 
     144        } 
     145      } else { 
     146        delete [] buffer; 
     147        /* 
     148        if (!RevertToSelf()) { 
     149          LOG_ERROR_STD(_T("Failed to revert to self: ") + error::lookup::last_error()); 
     150        } 
     151        */ 
     152        LOG_MESSAGE_STD(_T("Started tray in other user session: ") + strEx::itos(dwSessionId)); 
     153      } 
     154 
     155 
     156      CloseHandle(hToken); 
     157      return true; 
     158    } 
     159  } 
     160}; 
     161 
     162 
     163 
     164 
    28165 
    29166/** 
     
    62199        return -1; 
    63200      } 
     201      LOG_MESSAGE(_T("Service uninstalled!")); 
    64202    } else if ( _wcsicmp( _T("encrypt"), argv[1]+1 ) == 0 ) { 
    65203      g_bConsoleLog = true; 
     
    104242      LOG_MESSAGE(SZAPPNAME _T(" Version: ") SZVERSION _T(", Plattform: ") SZARCH); 
    105243    } else if ( _wcsicmp( _T("noboot"), argv[1]+1 ) == 0 ) { 
    106       mainClient.setBoot(false); 
    107244      g_bConsoleLog = false; 
    108245      mainClient.enableDebug(true); 
    109       mainClient.InitiateService(); 
     246      mainClient.initCore(false); 
    110247      int nRetCode = -1; 
    111248      if (argc>=4) 
     
    113250      else if (argc>=3) 
    114251        nRetCode = mainClient.commandLineExec(argv[2], argv[3], 0, NULL); 
    115       mainClient.TerminateService(); 
     252      mainClient.exitCore(false); 
    116253      return nRetCode; 
    117254    } else if ( _wcsicmp( _T("test"), argv[1]+1 ) == 0 ) { 
    118       std::wcout << "Launching test mode..." << std::endl; 
     255      bool server = false; 
     256      if (argc > 2 && _wcsicmp( _T("server"), argv[2] ) == 0 ) { 
     257        server = true; 
     258      } 
     259      std::wcout << "Launching test mode - " << (server?_T("server mode"):_T("client mode")) << std::endl; 
    119260      LOG_MESSAGE_STD(_T("Booting: " SZSERVICEDISPLAYNAME )); 
    120261      try { 
     
    123264        } 
    124265      } catch (const serviceControll::SCException& e) { 
    125         // Empty by design 
     266        e;// Empty by design 
    126267      } 
    127268      g_bConsoleLog = true; 
    128269      mainClient.enableDebug(true); 
    129       if (!mainClient.InitiateService()) { 
     270      if (!mainClient.initCore(true)) { 
    130271        LOG_ERROR_STD(_T("Service *NOT* started!")); 
    131272        return -1; 
    132273      } 
     274      if (server) 
     275        mainClient.startTrayIcon(0); 
    133276      LOG_MESSAGE_STD(_T("Using settings from: ") + Settings::getInstance()->getActiveType()); 
    134277      LOG_MESSAGE(_T("Enter command to inject or exit to terminate...")); 
     
    147290          std::wcout << _T("Setting debug log on...") << std::endl; 
    148291          mainClient.enableDebug(true); 
     292        } else if (s == _T("reattach")) { 
     293          std::wcout << _T("Reattaching to session 0") << std::endl; 
     294          mainClient.startTrayIcon(0); 
    149295        } else if (std::cin.peek() < 15) { 
    150296          buff += s; 
     
    166312        } 
    167313      } 
    168       mainClient.TerminateService(); 
     314      mainClient.exitCore(true); 
    169315      return 0; 
    170316    } else { 
     
    176322  } else if (argc > 2) { 
    177323    g_bConsoleLog = true; 
    178     mainClient.InitiateService(); 
     324    mainClient.initCore(true); 
    179325    if (argc>=3) 
    180326      nRetCode = mainClient.commandLineExec(argv[1], argv[2], argc-3, &argv[3]); 
    181327    else 
    182328      nRetCode = mainClient.commandLineExec(argv[1], argv[2], 0, NULL); 
    183     mainClient.TerminateService(); 
     329    mainClient.exitCore(true); 
    184330    return nRetCode; 
    185331  } else if (argc > 1) { 
     
    198344} 
    199345 
     346void NSClientT::session_error(std::wstring file, unsigned int line, std::wstring msg) { 
     347  NSAPIMessage(NSCAPI::error, file.c_str(), line, msg.c_str()); 
     348} 
     349 
     350 
     351 
     352 
    200353////////////////////////////////////////////////////////////////////////// 
    201354// Service functions 
    202355 
    203356/** 
    204  * Service control handler startup point. 
    205  * When the program is started as a service this will be the entry point. 
     357 * Initialize the program 
     358 * @param boot true if we shall boot all plugins 
     359 * @param attachIfPossible is true we will attach to a running instance. 
     360 * @return success 
     361 * @author mickem 
    206362 */ 
    207 bool NSClientT::InitiateService() { 
     363bool NSClientT::initCore(bool boot) { 
     364  LOG_MESSAGE(_T("Attempting to start NSCLient++ - " SZVERSION)); 
    208365  try { 
    209366    Settings::getInstance()->setFile(getBasePath(), _T("NSC.ini")); 
     
    211368      Settings::getInstance()->setInt(_T("log"), _T("debug"), 1); 
    212369    } 
     370    if (enable_shared_session_) 
     371      Settings::getInstance()->setInt(MAIN_SECTION_TITLE, MAIN_SHARED_SESSION, 1); 
     372    enable_shared_session_ = Settings::getInstance()->getInt(MAIN_SECTION_TITLE, MAIN_SHARED_SESSION, MAIN_SHARED_SESSION_DEFAULT); 
    213373  } catch (SettingsException e) { 
    214374    LOG_ERROR_STD(_T("Could not find settings: ") + e.getMessage()); 
     
    217377    LOG_ERROR_STD(_T("Unknown exception reading settings...")); 
    218378    return false; 
     379  } 
     380 
     381  if (enable_shared_session_) { 
     382    if (boot) { 
     383      try { 
     384        shared_server_.reset(new nsclient_session::shared_server_session(this)); 
     385        if (!shared_server_->session_exists()) { 
     386          shared_server_->create_new_session(); 
     387        } else { 
     388          LOG_ERROR_STD(_T("Session already exists cant create a new one!")); 
     389        } 
     390        startTrayIcons(); 
     391      } catch (nsclient_session::session_exception e) { 
     392        LOG_ERROR_STD(_T("Failed to create new session: ") + e.what()); 
     393        shared_server_ = NULL; 
     394      } catch (...) { 
     395        LOG_ERROR_STD(_T("Failed to create new session: Unknown exception")); 
     396        shared_server_ = NULL; 
     397      } 
     398    } else { 
     399      try { 
     400        std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); 
     401        shared_client_.reset(new nsclient_session::shared_client_session(id, this)); 
     402        if (shared_client_->session_exists()) { 
     403          shared_client_->attach_to_session(id); 
     404        } else { 
     405          LOG_ERROR_STD(_T("No session was found cant attach!")); 
     406        } 
     407        LOG_ERROR_STD(_T("Session is: ") + shared_client_->get_client_id()); 
     408      } catch (nsclient_session::session_exception e) { 
     409        LOG_ERROR_STD(_T("Failed to attach to session: ") + e.what()); 
     410        shared_client_ = NULL; 
     411      } catch (...) { 
     412        LOG_ERROR_STD(_T("Failed to attach to session: Unknown exception")); 
     413        shared_client_ = NULL; 
     414      } 
     415    } 
    219416  } 
    220417 
     
    238435    return false; 
    239436  } 
    240   if (boot_) { 
     437  if (boot) { 
    241438    try { 
    242439      SettingsT::sectionList list = Settings::getInstance()->getSection(_T("modules")); 
     
    256453      } 
    257454    } catch (SettingsException e) { 
    258       NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
     455      LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
    259456    } catch (...) { 
    260457      LOG_ERROR_STD(_T("Unknown exception when loading settings")); 
     
    268465    } 
    269466  } 
     467  LOG_MESSAGE_STD(_T("NSCLient++ - " SZVERSION) + _T(" Started!")); 
     468  return true; 
     469} 
     470 
     471/** 
     472 * Service control handler startup point. 
     473 * When the program is started as a service this will be the entry point. 
     474 */ 
     475bool NSClientT::InitiateService() { 
     476  if (!initCore(true)) 
     477    return false; 
     478/* 
     479  DWORD dwSessionId = remote_processes::getActiveSessionId(); 
     480  if (dwSessionId != 0xFFFFFFFF) 
     481    tray_starter::start(dwSessionId); 
     482  else 
     483    LOG_ERROR_STD(_T("Failed to start tray helper:" ) + error::lookup::last_error()); 
     484    */ 
     485  return true; 
     486} 
     487 
     488void NSClientT::startTrayIcons() { 
     489  if (shared_server_.get() == NULL) { 
     490    LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 
     491    return; 
     492  } 
     493  remote_processes::PWTS_SESSION_INFO list; 
     494  DWORD count; 
     495  if (!remote_processes::_WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE , 0, 1, &list, &count)) { 
     496    LOG_ERROR_STD(_T("Failed to enumerate sessions:" ) + error::lookup::last_error()); 
     497  } else { 
     498    LOG_DEBUG_STD(_T("Found ") + strEx::itos(count) + _T(" sessions")); 
     499    for (DWORD i=0;i<count;i++) { 
     500      LOG_DEBUG_STD(_T("Found session") + strEx::itos(list[i].SessionId) + _T(" state: ") + strEx::itos(list[i].State)); 
     501      if (list[i].State == remote_processes::_WTS_CONNECTSTATE_CLASS::WTSActive) { 
     502        startTrayIcon(list[i].SessionId); 
     503      } 
     504    } 
     505  } 
     506} 
     507void NSClientT::startTrayIcon(DWORD dwSessionId) { 
     508  if (shared_server_.get() == NULL) { 
     509    LOG_MESSAGE_STD(_T("No master session so tray icons not started")); 
     510    return; 
     511  } 
     512  if (!shared_server_->re_attach_client(dwSessionId)) { 
     513    if (!tray_starter::start(dwSessionId)) { 
     514      LOG_ERROR_STD(_T("Failed to start session (") + strEx::itos(dwSessionId) + _T("): " ) + error::lookup::last_error()); 
     515    } 
     516  } 
     517} 
     518 
     519bool NSClientT::exitCore(bool boot) { 
     520  LOG_MESSAGE(_T("Attempting to stop NSCLient++ - " SZVERSION)); 
     521  if (boot) { 
     522    try { 
     523      LOG_DEBUG_STD(_T("Stopping: NON Message Handling Plugins")); 
     524      mainClient.unloadPlugins(false); 
     525    } catch(NSPluginException e) { 
     526      std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 
     527    } catch(...) { 
     528      std::wcout << _T("UNknown exception raised: ") << std::endl;; 
     529    } 
     530  } 
     531  LOG_DEBUG_STD(_T("Stopping: COM helper")); 
     532  try { 
     533    com_helper_.unInitialize(); 
     534  } catch (com_helper::com_exception e) { 
     535    LOG_ERROR_STD(_T("COM exception: ") + e.getMessage()); 
     536  } catch (...) { 
     537    LOG_ERROR_STD(_T("Unknown exception uniniating COM...")); 
     538  } 
     539  LOG_DEBUG_STD(_T("Stopping: Socket Helpers")); 
     540  try { 
     541    simpleSocket::WSACleanup(); 
     542  } catch (simpleSocket::SocketException e) { 
     543    LOG_ERROR_STD(_T("Socket exception: ") + e.getMessage()); 
     544  } catch (...) { 
     545    LOG_ERROR_STD(_T("Unknown exception uniniating socket...")); 
     546  } 
     547  LOG_DEBUG_STD(_T("Stopping: Settings instance")); 
     548  Settings::destroyInstance(); 
     549  try { 
     550    if (shared_client_.get() != NULL) { 
     551      LOG_DEBUG_STD(_T("Stopping: shared client")); 
     552      shared_client_->set_handler(NULL); 
     553      shared_client_->close_session(); 
     554    } 
     555  } catch(nsclient_session::session_exception &e) { 
     556    std::wcout << _T("Exception closing shared client session: ") << e.what() << std::endl;; 
     557  } catch(...) { 
     558    std::wcout << _T("Exception closing shared client session: Unknown exception!") << std::endl;; 
     559  } 
     560  try { 
     561    if (shared_server_.get() != NULL) { 
     562      LOG_DEBUG_STD(_T("Stopping: shared server")); 
     563      shared_server_->set_handler(NULL); 
     564      shared_server_->close_session(); 
     565    } 
     566  } catch(...) { 
     567    std::wcout << _T("UNknown exception raised: ") << std::endl;; 
     568  } 
     569  if (boot) { 
     570    try { 
     571      LOG_DEBUG_STD(_T("Stopping: Message handling Plugins")); 
     572      mainClient.unloadPlugins(true); 
     573    } catch(NSPluginException e) { 
     574      std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 
     575    } catch(...) { 
     576      std::wcout << _T("UNknown exception raised: ") << std::endl;; 
     577    } 
     578  } 
     579  LOG_MESSAGE_STD(_T("NSCLient++ - " SZVERSION) + _T(" Stopped succcessfully")); 
    270580  return true; 
    271581} 
     
    275585 */ 
    276586void NSClientT::TerminateService(void) { 
    277   if (boot_) { 
    278     try { 
    279       mainClient.unloadPlugins(); 
    280     } catch(NSPluginException e) { 
    281       std::wcout << _T("Exception raised: ") << e.error_ << _T(" in module: ") << e.file_ << std::endl;; 
    282     } catch(...) { 
    283       std::wcout << _T("UNknown exception raised: ") << std::endl;; 
    284     } 
    285   } 
    286   try { 
    287     com_helper_.unInitialize(); 
    288   } catch (com_helper::com_exception e) { 
    289     LOG_ERROR_STD(_T("COM exception: ") + e.getMessage()); 
    290   } catch (...) { 
    291     LOG_ERROR_STD(_T("Unknown exception uniniating COM...")); 
    292   } 
    293   try { 
    294     simpleSocket::WSACleanup(); 
    295   } catch (simpleSocket::SocketException e) { 
    296     LOG_ERROR_STD(_T("Socket exception: ") + e.getMessage()); 
    297   } catch (...) { 
    298     LOG_ERROR_STD(_T("Unknown exception uniniating socket...")); 
    299   } 
    300   Settings::destroyInstance(); 
     587  exitCore(true); 
    301588} 
    302589 
     
    309596  mainClient.service_main(dwArgc, lpszArgv); 
    310597} 
     598DWORD WINAPI NSClientT::service_ctrl_dispatch_ex(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) { 
     599  LOG_ERROR_STD(_T("service_ctrl_dispatch_ex dispatching event: ") + strEx::itos(dwControl)); 
     600  return mainClient.service_ctrl_ex(dwControl, dwEventType, lpEventData, lpContext); 
     601} 
     602 
    311603/** 
    312604 * Forward this to the main service dispatcher helper class 
     
    314606 */ 
    315607void WINAPI NSClientT::service_ctrl_dispatch(DWORD dwCtrlCode) { 
    316   mainClient.service_ctrl(dwCtrlCode); 
    317 } 
     608  LOG_ERROR_STD(_T("service_ctrl_dispatch dispatching event: ") + strEx::itos(dwCtrlCode)); 
     609  mainClient.service_ctrl_ex(dwCtrlCode, NULL, NULL, NULL); 
     610} 
     611 
     612 
     613void NSClientT::service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType) { 
     614  LOG_MESSAGE_STD(_T("Got session change: ") + strEx::itos(dwSessionId)); 
     615  if (!logon) { 
     616    LOG_MESSAGE_STD(_T("Not a logon event: ") + strEx::itos(dwEventType)); 
     617    return; 
     618  } 
     619  tray_starter::start(dwSessionId); 
     620} 
     621 
    318622 
    319623////////////////////////////////////////////////////////////////////////// 
     
    383687 * Unload all plug-ins (in reversed order) 
    384688 */ 
    385 void NSClientT::unloadPlugins() { 
     689void NSClientT::unloadPlugins(bool unloadLoggers) { 
    386690  { 
    387691    WriteLock writeLock(&m_mutexRW, true, 10000); 
     
    391695    } 
    392696    commandHandlers_.clear(); 
    393     messageHandlers_.clear(); 
     697    if (unloadLoggers) 
     698      messageHandlers_.clear(); 
    394699  } 
    395700  { 
     
    401706    for (pluginList::size_type i=plugins_.size();i>0;i--) { 
    402707      NSCPlugin *p = plugins_[i-1]; 
    403       LOG_DEBUG_STD(_T("Unloading plugin: ") + p->getName() + _T("...")); 
     708      if (!unloadLoggers && p->hasMessageHandler()) { 
     709        LOG_DEBUG_STD(_T("Skipping log plugin: ") + p->getModule() + _T("...")); 
     710        continue; 
     711      } 
     712      LOG_DEBUG_STD(_T("Unloading plugin: ") + p->getModule() + _T("...")); 
    404713      p->unload(); 
    405714    } 
     
    413722    for (pluginList::size_type i=plugins_.size();i>0;i--) { 
    414723      NSCPlugin *p = plugins_[i-1]; 
    415       plugins_[i-1] = NULL; 
    416       delete p; 
    417     } 
    418     plugins_.clear(); 
     724      if (unloadLoggers || !p->hasMessageHandler()) { 
     725        LOG_DEBUG_STD(_T("Deleating plugin instance: ") + p->getModule() + _T("...")); 
     726        plugins_[i-1] = NULL; 
     727        delete p; 
     728        plugins_.erase(plugins_.begin() + i-1); 
     729        --i; 
     730      } 
     731    } 
     732    //plugins_.clear(); 
    419733  } 
    420734} 
     
    430744    (*it)->load_plugin(); 
    431745  } 
     746  plugins_loaded_ = true; 
    432747} 
    433748/** 
     
    498813      len = Settings::getInstance()->getInt(MAIN_SECTION_TITLE, MAIN_STRING_LENGTH, MAIN_STRING_LENGTH_DEFAULT); 
    499814    } catch (SettingsException &e) { 
    500       NSC_DEBUG_MSG(_T("Failed to get length: ") + e.getMessage()); 
     815      LOG_DEBUG_STD(_T("Failed to get length: ") + e.getMessage()); 
    501816      return MAIN_STRING_LENGTH_DEFAULT; 
    502817    } catch (...) { 
    503       NSC_LOG_ERROR(_T("Failed to get length: :(")); 
     818      LOG_ERROR(_T("Failed to get length: :(")); 
    504819      return MAIN_STRING_LENGTH_DEFAULT; 
    505820    } 
     
    509824 
    510825NSCAPI::nagiosReturn NSClientT::inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 
    511   unsigned int aLen = 0; 
    512   TCHAR ** aBuf = arrayBuffer::split2arrayBuffer(arguments, splitter, aLen, escape); 
    513   unsigned int buf_len = getBufferLength(); 
    514   TCHAR * mBuf = new TCHAR[buf_len+1]; mBuf[0] = '\0'; 
    515   TCHAR * pBuf = new TCHAR[buf_len+1]; pBuf[0] = '\0'; 
    516   NSCAPI::nagiosReturn ret = injectRAW(command.c_str(), aLen, aBuf, mBuf, buf_len, pBuf, buf_len); 
    517   arrayBuffer::destroyArrayBuffer(aBuf, aLen); 
    518   if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 
     826  if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 
     827    try { 
     828      return shared_client_->inject(command, arguments, splitter, escape, msg, perf); 
     829    } catch (nsclient_session::session_exception &e) { 
     830      LOG_ERROR_STD(_T("Failed to inject remote command: ") + e.what()); 
     831      return NSCAPI::returnCRIT; 
     832    } catch (...) { 
     833      LOG_ERROR_STD(_T("Failed to inject remote command: Unknown exception")); 
     834      return NSCAPI::returnCRIT; 
     835    } 
     836  } else { 
     837    unsigned int aLen = 0; 
     838    TCHAR ** aBuf = arrayBuffer::split2arrayBuffer(arguments, splitter, aLen, escape); 
     839    unsigned int buf_len = getBufferLength(); 
     840    TCHAR * mBuf = new TCHAR[buf_len+1]; mBuf[0] = '\0'; 
     841    TCHAR * pBuf = new TCHAR[buf_len+1]; pBuf[0] = '\0'; 
     842    NSCAPI::nagiosReturn ret = injectRAW(command.c_str(), aLen, aBuf, mBuf, buf_len, pBuf, buf_len); 
     843    arrayBuffer::destroyArrayBuffer(aBuf, aLen); 
     844    if ( (ret == NSCAPI::returnInvalidBufferLen) || (ret == NSCAPI::returnIgnored) ) { 
     845      delete [] mBuf; 
     846      delete [] pBuf; 
     847      return ret; 
     848    } 
     849    msg = mBuf; 
     850    perf = pBuf; 
    519851    delete [] mBuf; 
    520852    delete [] pBuf; 
    521853    return ret; 
    522854  } 
    523   msg = mBuf; 
    524   perf = pBuf; 
    525   delete [] mBuf; 
    526   delete [] pBuf; 
    527   return ret; 
    528855} 
    529856 
     
    544871    LOG_DEBUG_STD(_T("Injecting: ") + (std::wstring) command + _T(": ") + arrayBuffer::arrayBuffer2string(argument, argLen, _T(", "))); 
    545872  } 
    546   ReadLock readLock(&m_mutexRW, true, 5000); 
    547   if (!readLock.IsLocked()) { 
    548     LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    549     return NSCAPI::returnUNKNOWN; 
    550   } 
    551   for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 
     873  if (shared_client_.get() != NULL && shared_client_->hasMaster()) { 
    552874    try { 
    553       NSCAPI::nagiosReturn c = commandHandlers_[i]->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
    554       switch (c) { 
    555         case NSCAPI::returnInvalidBufferLen: 
    556           LOG_ERROR(_T("UNKNOWN: Return buffer to small to handle this command.")); 
    557           return c; 
    558         case NSCAPI::returnIgnored: 
    559           break; 
    560         case NSCAPI::returnOK: 
    561         case NSCAPI::returnWARN: 
    562         case NSCAPI::returnCRIT: 
    563         case NSCAPI::returnUNKNOWN: 
    564           LOG_DEBUG_STD(_T("Injected Result: ") + NSCHelper::translateReturn(c) + _T(" '") + (std::wstring)(returnMessageBuffer) + _T("'")); 
    565           LOG_DEBUG_STD(_T("Injected Performance Result: '") +(std::wstring)(returnPerfBuffer) + _T("'")); 
    566           return c; 
    567         default: 
    568           LOG_ERROR_STD(_T("Unknown error from handleCommand: ") + strEx::itos(c) + _T(" the injected command was: ") + (std::wstring)command); 
    569           return c; 
    570       } 
    571     } catch(const NSPluginException& e) { 
    572       LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
    573       return NSCAPI::returnCRIT; 
    574     } catch(...) { 
    575       LOG_ERROR_STD(_T("Unknown exception raised in module")); 
    576       return NSCAPI::returnCRIT; 
    577     } 
    578   } 
    579   LOG_MESSAGE_STD(_T("No handler for command: '") + command + _T("'")); 
    580   return NSCAPI::returnIgnored; 
     875      std::wstring msg, perf; 
     876      int returnCode = shared_client_->inject(command, arrayBuffer::arrayBuffer2string(argument, argLen, _T(" ")), L' ', true, msg, perf); 
     877      NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, msg, returnCode); 
     878      return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, perf, returnCode); 
     879    } catch (nsclient_session::session_exception &e) { 
     880      LOG_ERROR_STD(_T("Failed to inject remote command: ") + e.what()); 
     881      int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command: ") + e.what(), NSCAPI::returnCRIT); 
     882      return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 
     883    } catch (...) { 
     884      LOG_ERROR_STD(_T("Failed to inject remote command: Unknown exception")); 
     885      int returnCode = NSCHelper::wrapReturnString(returnMessageBuffer, returnMessageBufferLen, _T("Failed to inject remote command:  + e.what()"), NSCAPI::returnCRIT); 
     886      return NSCHelper::wrapReturnString(returnPerfBuffer, returnPerfBufferLen, _T(""), returnCode); 
     887    } 
     888  } else { 
     889    ReadLock readLock(&m_mutexRW, true, 5000); 
     890    if (!readLock.IsLocked()) { 
     891      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
     892      return NSCAPI::returnUNKNOWN; 
     893    } 
     894    for (pluginList::size_type i = 0; i < commandHandlers_.size(); i++) { 
     895      try { 
     896        NSCAPI::nagiosReturn c = commandHandlers_[i]->handleCommand(command, argLen, argument, returnMessageBuffer, returnMessageBufferLen, returnPerfBuffer, returnPerfBufferLen); 
     897        switch (c) { 
     898          case NSCAPI::returnInvalidBufferLen: 
     899            LOG_ERROR(_T("UNKNOWN: Return buffer to small to handle this command.")); 
     900            return c; 
     901          case NSCAPI::returnIgnored: 
     902            break; 
     903          case NSCAPI::returnOK: 
     904          case NSCAPI::returnWARN: 
     905          case NSCAPI::returnCRIT: 
     906          case NSCAPI::returnUNKNOWN: 
     907            LOG_DEBUG_STD(_T("Injected Result: ") + NSCHelper::translateReturn(c) + _T(" '") + (std::wstring)(returnMessageBuffer) + _T("'")); 
     908            LOG_DEBUG_STD(_T("Injected Performance Result: '") +(std::wstring)(returnPerfBuffer) + _T("'")); 
     909            return c; 
     910          default: 
     911            LOG_ERROR_STD(_T("Unknown error from handleCommand: ") + strEx::itos(c) + _T(" the injected command was: ") + (std::wstring)command); 
     912            return c; 
     913        } 
     914      } catch(const NSPluginException& e) { 
     915        LOG_ERROR_STD(_T("Exception raised: ") + e.error_ + _T(" in module: ") + e.file_); 
     916        return NSCAPI::returnCRIT; 
     917      } catch(...) { 
     918        LOG_ERROR_STD(_T("Unknown exception raised in module")); 
     919        return NSCAPI::returnCRIT; 
     920      } 
     921    } 
     922    LOG_MESSAGE_STD(_T("No handler for command: '") + command + _T("'")); 
     923    return NSCAPI::returnIgnored; 
     924  } 
    581925} 
    582926 
     
    606950  if ((msgType == NSCAPI::debug)&&(!logDebug())) { 
    607951    return; 
     952  } 
     953  if (shared_server_.get() != NULL && shared_server_->hasClients()) { 
     954    try { 
     955      shared_server_->sendLogMessageToClients(msgType, file, line, message); 
     956    } catch (nsclient_session::session_exception e) { 
     957      std::wcout << _T("Failed to send message to clients: ") << e.what() << std::endl; 
     958    } 
    608959  } 
    609960  std::wstring file_stl = file; 
     
    644995      std::cout << k << " " << strEx::wstring_to_string(file_stl) << "(" << line << ") " << strEx::wstring_to_string(message) << std::endl; 
    645996    } 
    646     for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
    647       try { 
    648         messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
    649       } catch(const NSPluginException& e) { 
    650         // Here we are pretty much fucked! (as logging this might cause a loop :) 
    651         std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 
    652         std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 
     997    if (messageHandlers_.size() == 0 || !plugins_loaded_) { 
     998      log_cache_.push_back(cached_log_entry(msgType, file, line, message)); 
     999    } else { 
     1000      if (log_cache_.size() > 0) { 
     1001        std::wcout << _T("*** SENDING CACHE***") << std::endl; 
     1002        for (log_cache_type::const_iterator cit=log_cache_.begin();cit!=log_cache_.end();++cit) { 
     1003          for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     1004            try { 
     1005              messageHandlers_[i]->handleMessage((*cit).msgType, (_T("CACHE") + (*cit).file).c_str(), (*cit).line, (*cit).message.c_str()); 
     1006            } catch(const NSPluginException& e) { 
     1007              // Here we are pretty much fucked! (as logging this might cause a loop :) 
     1008              std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 
     1009              std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 
     1010            } 
     1011          } 
     1012        } 
     1013        log_cache_.clear(); 
     1014      } 
     1015      for (pluginList::size_type i = 0; i< messageHandlers_.size(); i++) { 
     1016        try { 
     1017          messageHandlers_[i]->handleMessage(msgType, file, line, message.c_str()); 
     1018        } catch(const NSPluginException& e) { 
     1019          // Here we are pretty much fucked! (as logging this might cause a loop :) 
     1020          std::wcout << _T("Caught: ") << e.error_ << _T(" when trying to log a message...") << std::endl; 
     1021          std::wcout << _T("This is *really really* bad, now the world is about to end...") << std::endl; 
     1022        } 
    6531023      } 
    6541024    } 
     
    6731043    Settings::getInstance()->setFile(basePath, _T("NSC.ini")); 
    6741044  } catch (SettingsException e) { 
    675     NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
     1045    LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
    6761046  } 
    6771047  return basePath; 
     
    6831053    return NSCHelper::wrapReturnString(buffer, bufLen, Settings::getInstance()->getString(section, key, defaultValue), NSCAPI::isSuccess); 
    6841054  } catch (...) { 
    685     NSC_LOG_ERROR_STD(_T("Failed to getString: ") + key); 
     1055    LOG_ERROR_STD(_T("Failed to getString: ") + key); 
    6861056    return NSCAPI::hasFailed; 
    6871057  } 
     
    6911061    return Settings::getInstance()->getInt(section, key, defaultValue); 
    6921062  } catch (SettingsException e) { 
    693     NSC_LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
     1063    LOG_ERROR_STD(_T("Failed to set settings file") + e.getMessage()); 
    6941064    return defaultValue; 
    6951065  } 
     
    7201090    return NSCAPI::isSuccess; 
    7211091  } catch (...) { 
    722     NSC_LOG_ERROR_STD(_T("Failed to getSection: ") + section); 
     1092    LOG_ERROR_STD(_T("Failed to getSection: ") + section); 
    7231093    return NSCAPI::hasFailed; 
    7241094  } 
     
    8481218    Settings::getInstance()->setString(section, key, value); 
    8491219  } catch (...) { 
    850     NSC_LOG_ERROR_STD(_T("Failed to setString: ") + key); 
     1220    LOG_ERROR_STD(_T("Failed to setString: ") + key); 
    8511221    return NSCAPI::hasFailed; 
    8521222  } 
     
    8571227    Settings::getInstance()->setInt(section, key, value); 
    8581228  } catch (...) { 
    859     NSC_LOG_ERROR_STD(_T("Failed to setInt: ") + key); 
     1229    LOG_ERROR_STD(_T("Failed to setInt: ") + key); 
    8601230    return NSCAPI::hasFailed; 
    8611231  } 
     
    8741244    return NSCAPI::hasFailed; 
    8751245  } catch (...) { 
    876     NSC_LOG_ERROR_STD(_T("Failed to write settings")); 
     1246    LOG_ERROR_STD(_T("Failed to write settings")); 
    8771247    return NSCAPI::hasFailed; 
    8781248  } 
     
    8911261    return NSCAPI::hasFailed; 
    8921262  } catch (...) { 
    893     NSC_LOG_ERROR_STD(_T("Failed to read settings")); 
     1263    LOG_ERROR_STD(_T("Failed to read settings")); 
    8941264    return NSCAPI::hasFailed; 
    8951265  } 
  • NSClient++.h

    r367bf20 rc0522cd  
    3030#include <map> 
    3131#include <com_helpers.hpp> 
    32  
     32#include <nsclient_session.hpp> 
    3333 
    3434/** 
     
    5757 * 
    5858 */ 
    59 class NSClientT { 
     59class NSClientT : public nsclient_session::session_handler_interface { 
     60 
    6061private: 
     62 
     63  class NSException { 
     64    std::wstring what_; 
     65  public: 
     66    NSException(std::wstring what) : what_(what){} 
     67    std::wstring what() { 
     68      return what_; 
     69    } 
     70  }; 
     71  struct cached_log_entry { 
     72    cached_log_entry(int msgType_, std::wstring file_, int line_, std::wstring message_)  
     73      : msgType(msgType_), 
     74      file(file_), 
     75      line(line_), 
     76      message(message_) 
     77    {} 
     78    int msgType; 
     79    std::wstring file; 
     80    int line; 
     81    std::wstring message; 
     82  }; 
     83 
    6184  typedef NSCPlugin* plugin_type; 
    6285  typedef std::vector<plugin_type> pluginList; 
    6386  typedef std::map<std::wstring,std::wstring> cmdMap; 
     87  typedef std::list<cached_log_entry> log_cache_type; 
    6488  pluginList plugins_; 
    6589  pluginList commandHandlers_; 
     
    7397  typedef enum log_status {log_unknown, log_debug, log_nodebug }; 
    7498  log_status debug_; 
    75   bool boot_; 
    7699  com_helper::initialize_com com_helper_; 
     100  std::auto_ptr<nsclient_session::shared_client_session> shared_client_; 
     101  std::auto_ptr<nsclient_session::shared_server_session> shared_server_; 
     102  log_cache_type log_cache_; 
     103  bool plugins_loaded_; 
     104  bool enable_shared_session_; 
    77105 
    78106public: 
    79107  // c-tor, d-tor 
    80   NSClientT(void) : debug_(log_unknown), boot_(true) {} 
     108  NSClientT(void) : debug_(log_unknown), plugins_loaded_(false), enable_shared_session_(false) {} 
    81109  virtual ~NSClientT(void) {} 
    82110  void enableDebug(bool debug = true) { 
     
    86114      debug_ = log_nodebug; 
    87115  } 
    88   void setBoot(bool boot = true) { 
    89     boot_ = boot; 
    90   } 
    91116 
    92117  // Service helper functions 
    93118  bool InitiateService(); 
    94119  void TerminateService(void); 
     120  bool initCore(bool boot); 
     121  bool exitCore(bool boot); 
    95122  static void WINAPI service_main_dispatch(DWORD dwArgc, LPTSTR *lpszArgv); 
    96123  static void WINAPI service_ctrl_dispatch(DWORD dwCtrlCode); 
     124  static DWORD WINAPI service_ctrl_dispatch_ex(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext); 
     125  void service_on_session_changed(DWORD dwSessionId, bool logon, DWORD dwEventType); 
    97126 
    98127  // Member functions 
     
    108137  plugin_type loadPlugin(const std::wstring plugin); 
    109138  void loadPlugins(void); 
    110   void unloadPlugins(void); 
     139  void unloadPlugins(bool unloadLoggers); 
    111140  std::wstring describeCommand(std::wstring command); 
    112141  std::list<std::wstring> getAllCommandNames(); 
    113142  void registerCommand(std::wstring cmd, std::wstring desc); 
    114143  unsigned int getBufferLength(); 
     144  void startTrayIcons(); 
     145  void startTrayIcon(DWORD dwSessionId); 
    115146 
    116147  bool logDebug(); 
     148 
     149  // Shared session interface: 
     150  void session_error(std::wstring file, unsigned int line, std::wstring msg); 
     151  void session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message) { 
     152    reportMessage(msgType, file, line, message); 
     153  } 
     154  int session_inject(std::wstring command, std::wstring arguments, std::wstring splitter, bool escape, std::wstring &msg, std::wstring & perf) { 
     155    return inject(command, arguments, splitter[0], escape, msg, perf); 
     156  } 
     157 
     158 
    117159 
    118160private: 
  • changelog

    r846bbe4 rc0522cd  
    55 * Improved socket performance (would be nice if we could be used as a "hub") 
    66 
     72008-08-16 MickeM 
     8 * *WARNING* THIS IS VERY VERY UNSTABEL (possibly) 
     9 * *WARNING* A lot of new untested code here so dont run in production enviornments :) 
     10 + Added shared session so system tray can communicate with master 
     11 + Added new system tray handlig (via TS so FUS should work with it) 
     12 + Added new option [System] / shared_session=0 (or 1) to enable / disable the new shared memory framework (it is for now disabled by default) 
     13   If you want to try this remember to change that option but also beware! it is dagerous and not finnished and and also there is as of now no security at all. 
     14 
    7152008-08-09 MickeM 
    8  + Added ChangeWindowMessageFilter so systray should not work on vista and beyond! 
     16 + Added ChangeWindowMessageFilter so systray should maybe work on vista and beyond! 
    917 
    10182008-07-28 MickeM 
  • helpers/UploadBinaries/UploadBinaries.vcproj

    r846bbe4 rc0522cd  
    381381      <Tool 
    382382        Name="VCCustomBuildTool" 
    383         CommandLine="echo Making archive&#x0D;&#x0A;7z.exe a -r -tzip -bd &quot;$(TargetDir)\NSClient++-$(PlatformName).zip&quot; &quot;$(TargetDir)\*&quot;&#x0D;&#x0A;echo Renaming archive&#x0D;&#x0A;postbuild.pl &quot;$(TargetDir)\NSClient++-$(PlatformName).zip&quot; zip&#x0D;&#x0A;echo Sending to server&#x0D;&#x0A;pscp.exe &quot;$(TargetDir)\*.zip&quot; mickem@ssl.nakednuns.org:/var/www/files/nightly/&#x0D;&#x0A;" 
     383        CommandLine="echo Making archive&#x0D;&#x0A;7z.exe a -r -tzip -bd &quot;$(TargetDir)\NSClient++-$(PlatformName).zip&quot; &quot;$(TargetDir)\*&quot;&#x0D;&#x0A;echo Renaming archive&#x0D;&#x0A;postbuild.pl &quot;$(TargetDir)\NSClient++-$(PlatformName).zip&quot; zip&#x0D;&#x0A;echo Sending to server&#x0D;&#x0A;pscp.exe &quot;$(TargetDir)\*.zip&quot; nscp@druss.medin.name:/var/www/files/nightly/&#x0D;&#x0A;" 
    384384        Outputs="foo" 
    385385      /> 
  • helpers/UploadInstaller/UploadInstaller.vcproj

    r846bbe4 rc0522cd  
    247247      <Tool 
    248248        Name="VCCustomBuildTool" 
    249         CommandLine="echo Renaming archive&#x0D;&#x0A;echo mkdir &quot;$(OutDir)&quot;&#x0D;&#x0A;mkdir &quot;$(OutDir)&quot;&#x0D;&#x0A;cmd /c del &quot;$(OutDir)\*.msi&quot;&quot;&#x0D;&#x0A;cmd /c copy &quot;..\installer\bin\$(ConfigurationName)\NSClient++.msi&quot; &quot;$(OutDir)\NSClient++-$(PlatformName).msi&quot;&quot;&#x0D;&#x0A;postbuild.pl &quot;$(TargetDir)\NSClient++-$(PlatformName).msi&quot; msi&#x0D;&#x0A;echo Sending to server&#x0D;&#x0A;pscp.exe &quot;$(TargetDir)\*.msi&quot; mickem@ssl.nakednuns.org:/var/www/files/nightly/&#x0D;&#x0A;" 
     249        CommandLine="echo Renaming archive&#x0D;&#x0A;echo mkdir &quot;$(OutDir)&quot;&#x0D;&#x0A;mkdir &quot;$(OutDir)&quot;&#x0D;&#x0A;cmd /c del &quot;$(OutDir)\*.msi&quot;&quot;&#x0D;&#x0A;cmd /c copy &quot;..\installer\bin\$(ConfigurationName)\NSClient++.msi&quot; &quot;$(OutDir)\NSClient++-$(PlatformName).msi&quot;&quot;&#x0D;&#x0A;postbuild.pl &quot;$(TargetDir)\NSClient++-$(PlatformName).msi&quot; msi&#x0D;&#x0A;echo Sending to server&#x0D;&#x0A;pscp.exe &quot;$(TargetDir)\*.msi&quot; nscp@druss.medin.name:/var/www/files/nightly/&#x0D;&#x0A;" 
    250250        Outputs="foo" 
    251251      /> 
  • include/Mutex.h

    r394f7a1 rc0522cd  
    2525#include <windows.h> 
    2626#include <iostream> 
     27#include <error.hpp> 
     28 
     29class mutex_exception { 
     30  std::wstring what_; 
     31public: 
     32  mutex_exception(std::wstring what) : what_(what) {} 
     33  std::wstring what() { return what_; } 
     34}; 
    2735 
    2836/** 
     
    5058 */ 
    5159class MutexHandler { 
     60public: 
    5261private: 
    5362  HANDLE hMutex; 
     63  DWORD dwWaitResult; 
     64  bool bCreated; 
    5465public: 
    5566  /** 
     
    5768   * Creates an unnamed mutex. 
    5869   */ 
    59   MutexHandler() : hMutex(NULL) { 
    60     hMutex = CreateMutex(NULL, FALSE, NULL); 
     70  MutexHandler(std::wstring name = _T("")) : hMutex(NULL), dwWaitResult(0), bCreated(false) { 
     71    //std::wcout << _T("Creating mutex: ") << name << std::endl; 
     72    hMutex = CreateMutex(NULL, FALSE, name.empty()?NULL:name.c_str()); 
    6173    if (hMutex == NULL && GetLastError() == ERROR_ALREADY_EXISTS ) 
    62       hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NULL); 
    63     if (hMutex == NULL) { 
    64       std::wcout << _T("Error in mutex creation: ") << GetLastError() << std::endl; 
    65     } 
     74      hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name.empty()?NULL:name.c_str()); 
     75    else  
     76      bCreated = true; 
     77    if (hMutex == NULL) 
     78      throw mutex_exception(_T("Failed to create mutex: ") + error::lookup::last_error()); 
    6679  } 
    6780  /** 
     
    7487    hMutex = NULL; 
    7588  } 
     89  void close() { 
     90    if (hMutex) 
     91      CloseHandle(hMutex); 
     92    hMutex = NULL; 
     93  } 
     94  bool mutexWasCreated() { 
     95    return bCreated; 
     96  } 
    7697  /** 
    7798   * HANDLe cast operator to retrieve the handle from the enclosed mutex object. 
     
    80101  operator HANDLE () const { 
    81102    return hMutex; 
     103  } 
     104  /** 
     105  * Release the mutex 
     106  */ 
     107  void releaseLock() { 
     108    if (hMutex == NULL) 
     109      throw mutex_exception(_T("Failed to release mutex lock (mutex handle is null)")); 
     110    if (!ReleaseMutex(hMutex)) 
     111      throw mutex_exception(_T("Failed to relase the mutex: ") + error::lookup::last_error()); 
     112  } 
     113  /** 
     114  * Waits for the mutex object. 
     115  * @timeout The timeout before abandoning wait 
     116  */ 
     117  bool accuireLock(DWORD timeout = 5000L) { 
     118    if (hMutex == NULL) 
     119      throw mutex_exception(_T("Failed to get mutex lock (mutex handle is null)")); 
     120    dwWaitResult = WaitForSingleObject(hMutex, timeout); 
     121    switch (dwWaitResult) { 
     122      // The thread got mutex ownership. 
     123    case WAIT_OBJECT_0: 
     124      return true; 
     125    case WAIT_TIMEOUT:  
     126      return false; 
     127    case WAIT_ABANDONED:  
     128      return true; 
     129    default: 
     130      throw mutex_exception(_T("Unknown returncode from the mutex: ") + strEx::itos(dwWaitResult)); 
     131       
     132    } 
     133  } 
     134  /** 
     135  * Get the result of the wait operation. 
     136  * @return Result of the wait operation 
     137  */ 
     138  DWORD getWaitResult() const { 
     139    return dwWaitResult; 
    82140  } 
    83141}; 
     
    125183  MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { 
    126184    if (hMutex_ == NULL) { 
    127       std::wcout << _T("Error in mutex lock: ") << std::endl; 
     185      throw mutex_exception(_T("Failed to get mutex lock (mutex handle is null)")); 
     186      /* 
    128187      bHasMutex = false; 
    129188      return; 
     189      */ 
    130190    } 
    131191    dwWaitResult = WaitForSingleObject(hMutex_, timeout); 
     
    135195      bHasMutex = true; 
    136196      break; 
    137         case WAIT_TIMEOUT:  
    138       bHasMutex = false; 
    139       break; 
    140         case WAIT_ABANDONED:  
     197        case WAIT_TIMEOUT: 
     198      bHasMutex = false; 
     199      break; 
     200        case WAIT_ABANDONED: 
    141201      bHasMutex = false; 
    142202      break; 
     
    195255  void lock(DWORD timeout = 5000L) { 
    196256    if (hMutex_ == NULL) { 
     257      throw mutex_exception(_T("Failed to get mutex lock (mutex handle is null)")); 
     258      /* 
    197259      std::wcout << _T("Error in mutex lock: ") << std::endl; 
    198260      bHasMutex = false; 
    199261      return; 
     262      */ 
    200263    } 
    201264    dwWaitResult = WaitForSingleObject(hMutex_, timeout); 
  • include/NSCHelper.cpp

    r846bbe4 rc0522cd  
    146146  lpNSAPIMessage fNSAPIMessage = NULL; 
    147147  lpNSAPIStopServer fNSAPIStopServer = NULL; 
     148  lpNSAPIExit fNSAPIExit = NULL; 
    148149  lpNSAPIInject fNSAPIInject = NULL; 
    149150  lpNSAPICheckLogMessages fNSAPICheckLogMessages = NULL; 
     
    310311} 
    311312/** 
     313 * Close the program (usefull for tray/testmode) without stopping the service (unless this is the service). 
     314 * @author mickem 
     315 */ 
     316void NSCModuleHelper::Exit(void) { 
     317  if (fNSAPIExit) 
     318    fNSAPIExit(); 
     319} 
     320/** 
    312321 * Retrieve a string from the settings subsystem (INI-file) 
    313322 * Might possibly be located in the registry in the future. 
     
    609618  NSCModuleHelper::fNSAPIMessage = (NSCModuleHelper::lpNSAPIMessage)f(_T("NSAPIMessage")); 
    610619  NSCModuleHelper::fNSAPIStopServer = (NSCModuleHelper::lpNSAPIStopServer)f(_T("NSAPIStopServer")); 
     620  NSCModuleHelper::fNSAPIExit = (NSCModuleHelper::lpNSAPIExit)f(_T("NSAPIExit")); 
    611621  NSCModuleHelper::fNSAPIInject = (NSCModuleHelper::lpNSAPIInject)f(_T("NSAPIInject")); 
    612622  NSCModuleHelper::fNSAPIGetBasePath = (NSCModuleHelper::lpNSAPIGetBasePath)f(_T("NSAPIGetBasePath")); 
  • include/NSCHelper.h

    r796d8ff rc0522cd  
    110110  typedef void (*lpNSAPIMessage)(int, const TCHAR*, const int, const TCHAR*); 
    111111  typedef NSCAPI::errorReturn (*lpNSAPIStopServer)(void); 
     112  typedef NSCAPI::errorReturn (*lpNSAPIExit)(void); 
    112113  typedef NSCAPI::nagiosReturn (*lpNSAPIInject)(const TCHAR*, const unsigned int, TCHAR **, TCHAR *, unsigned int, TCHAR *, unsigned int); 
    113114  typedef void* (*lpNSAPILoader)(TCHAR*); 
     
    137138  NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, TCHAR splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 
    138139  void StopService(void); 
     140  void Exit(void); 
    139141  std::wstring getBasePath(); 
    140142  bool logDebug(); 
     
    333335    } catch (...) { \ 
    334336      NSC_LOG_CRITICAL(_T("Unknown exception in: commandLineExec(...)")); \ 
     337      std::wcerr << _T("Unknown exception in: commandLineExec(...)") << std::endl; \ 
    335338      return NSCAPI::hasFailed; \ 
    336339    } \ 
  • include/NTService.h

    r978bd31 rc0522cd  
    2222 
    2323#include <string> 
     24#include <sysinfo.h> 
    2425 
    2526 
     
    8081  void service_main(DWORD dwArgc, LPTSTR *lpszArgv) 
    8182  { 
    82     // register our service control handler: 
    83     sshStatusHandle = RegisterServiceCtrlHandler( SZSERVICENAME, TBase::service_ctrl_dispatch); 
     83    if (systemInfo::isAboveW2K(systemInfo::getOSVersion())) { 
     84      ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SESSIONCHANGE; 
     85      sshStatusHandle = RegisterServiceCtrlHandlerEx( SZSERVICENAME, TBase::service_ctrl_dispatch_ex, NULL); 
     86    } else { 
     87      // register our service control handler: 
     88      sshStatusHandle = RegisterServiceCtrlHandler( SZSERVICENAME, TBase::service_ctrl_dispatch); 
     89    } 
    8490 
    8591    // SERVICE_STATUS members that don't change in example 
     
    100106  } 
    101107 
    102  
    103   void service_ctrl(DWORD dwCtrlCode) { 
     108  typedef struct tagWTSSESSION_NOTIFICATION 
     109  { 
     110    DWORD cbSize; 
     111    DWORD dwSessionId; 
     112 
     113  } WTSSESSION_NOTIFICATION, *PWTSSESSION_NOTIFICATION; 
     114#define WTS_SESSION_LOGON                  0x5 
     115#define WTS_SESSION_LOGOFF                 0x6 
     116 
     117  DWORD service_ctrl_ex(DWORD dwCtrlCode, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) { 
    104118    switch(dwCtrlCode)  
    105119    { 
     
    107121      ReportStatusToSCMgr(SERVICE_STOP_PENDING, NO_ERROR, 0); 
    108122      ServiceStop(); 
    109       return; 
     123      return 0; 
    110124 
    111125    case SERVICE_CONTROL_INTERROGATE: 
    112126      break; 
    113127 
     128    case SERVICE_CONTROL_SESSIONCHANGE: 
     129      if (lpEventData != NULL && dwEventType == WTS_SESSION_LOGON) 
     130        service_on_session_changed(reinterpret_cast<WTSSESSION_NOTIFICATION*>(lpEventData)->dwSessionId, true, dwEventType); 
     131      else if (lpEventData != NULL && dwEventType == WTS_SESSION_LOGOFF) 
     132        service_on_session_changed(reinterpret_cast<WTSSESSION_NOTIFICATION*>(lpEventData)->dwSessionId, false, dwEventType); 
     133      else { 
     134        service_on_session_changed(reinterpret_cast<WTSSESSION_NOTIFICATION*>(lpEventData)->dwSessionId, false, dwEventType); 
     135      } 
     136      break; 
     137 
    114138    default: 
    115139      break; 
     
    117141    } 
    118142    ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0); 
     143    return 0; 
    119144  } 
    120145 
     
    141166      ssStatus.dwControlsAccepted = 0; 
    142167    else 
    143       ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; 
     168      ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP| SERVICE_ACCEPT_SESSIONCHANGE; 
    144169 
    145170    ssStatus.dwCurrentState = dwCurrentState; 
  • include/ServiceCmd.cpp

    rb5ef837 rc0522cd  
    9595    CloseServiceHandle(schSCManager); 
    9696    if (result != TRUE) 
    97       throw SCException(_T("Could not query service information")); 
     97      throw SCException(_T("Could not change service information")); 
    9898  } 
    9999 
  • include/config.h

    rda1c7e1 rc0522cd  
    8080#define NSCLIENT_SETTINGS_READ_TIMEOUT _T("socket_timeout") 
    8181#define NSCLIENT_SETTINGS_READ_TIMEOUT_DEFAULT 30 
     82#define NSCLIENT_SETTINGS_SYSTRAY_EXE _T("systray_exe") 
     83#define NSCLIENT_SETTINGS_SYSTRAY_EXE_DEFAULT _T("systray.exe") 
    8284 
    8385// NRPE Settings headlines 
     
    198200#define LOG_DATEMASK _T("date_mask") 
    199201#define LOG_DATEMASK_DEFAULT _T("%Y-%m-%d %H:%M:%S") 
     202#define LOG_ROOT _T("root_folder") 
     203#define LOG_ROOT_DEFAULT _T("exe") 
    200204 
    201205// Main Settings 
     
    216220#define MAIN_STRING_LENGTH _T("string_length") 
    217221#define MAIN_STRING_LENGTH_DEFAULT 4096 
    218  
    219  
    220 // LOA Config itemns 
     222#define MAIN_SHARED_SESSION _T("shared_session") 
     223#define MAIN_SHARED_SESSION_DEFAULT 0 
     224 
     225 
     226// LOA Config items 
    221227#define LUA_SCRIPT_SECTION_TITLE _T("LUA Scripts") 
    222228 
  • include/strEx.h

    r846bbe4 rc0522cd  
    3737  class string_exception : public std::exception { 
    3838    std::wstring _what; 
     39  public: 
    3940    string_exception(std::wstring what) : _what(what) {} 
    4041    std::wstring what() { 
     
    6869  inline std::string wstring_to_string( const wchar_t* pStr, int len) { 
    6970    if (pStr == NULL) 
    70       throw string_exception("Invalid pointer in wstring_to_string"); 
     71      throw string_exception(_T("Invalid pointer in wstring_to_string")); 
    7172    if (len < 0 && len != -1)  
    72       throw string_exception("Invalid string length in wstring_to_string"); 
     73      throw string_exception(_T("Invalid string length in wstring_to_string")); 
    7374 
    7475    // figure out how many narrow characters we are going to get  
     
    9495  inline std::wstring string_to_wstring( const char* pStr , int len ) { 
    9596    if (pStr == NULL) 
    96       throw string_exception("Invalid pointer in wstring_to_string"); 
     97      throw string_exception(_T("Invalid pointer in wstring_to_string")); 
    9798    if (len < 0 && len != -1)  
    98       throw string_exception("Invalid string length in wstring_to_string"); 
     99      throw string_exception(_T("Invalid string length in wstring_to_string")); 
    99100 
    100101    // figure out how many wide characters we are going to get  
     
    212213    } 
    213214  } 
     215  inline std::wstring ctos(TCHAR c) { 
     216    return std::wstring(c,1); 
     217  } 
    214218  inline std::wstring itos(unsigned int i) { 
    215219    std::wstringstream ss; 
  • modules/CheckDisk/CheckDisk-2005.vcproj

    r3f569d3 rc0522cd  
    188188      Name="Release|Win32" 
    189189      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    190       IntermediateDirectory="$(ConfigurationName)" 
     190      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    191191      ConfigurationType="2" 
    192192      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    267267      Name="Release|x64" 
    268268      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    269       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     269      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    270270      ConfigurationType="2" 
    271271      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/CheckEventLog/CheckEventLog-2005.vcproj

    r367bf20 rc0522cd  
    2525      Name="Release|Win32" 
    2626      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    27       IntermediateDirectory="$(ConfigurationName)" 
     27      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    2828      ConfigurationType="2" 
    2929      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    105105      Name="Release|x64" 
    106106      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    107       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     107      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    108108      ConfigurationType="2" 
    109109      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/CheckExternalScripts/CheckExternalScripts-2005.vcproj

    rdff5db9 rc0522cd  
    193193      Name="Release|Win32" 
    194194      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    195       IntermediateDirectory="$(ConfigurationName)" 
     195      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    196196      ConfigurationType="2" 
    197197      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    274274      Name="Release|x64" 
    275275      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    276       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     276      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    277277      ConfigurationType="2" 
    278278      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/CheckHelpers/CheckHelpers-2005.vcproj

    r3f569d3 rc0522cd  
    188188      Name="Release|Win32" 
    189189      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    190       IntermediateDirectory="$(ConfigurationName)" 
     190      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    191191      ConfigurationType="2" 
    192192      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    267267      Name="Release|x64" 
    268268      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    269       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     269      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    270270      ConfigurationType="2" 
    271271      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/CheckSystem/CheckSystem-2005.vcproj

    r3f569d3 rc0522cd  
    190190      Name="Release|Win32" 
    191191      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    192       IntermediateDirectory="$(ConfigurationName)" 
     192      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    193193      ConfigurationType="2" 
    194194      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    270270      Name="Release|x64" 
    271271      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    272       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     272      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    273273      ConfigurationType="2" 
    274274      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/CheckTaskSched/CheckTaskSched-2005.vcproj

    rda1c7e1 rc0522cd  
    153153      <Tool 
    154154        Name="VCLinkerTool" 
    155         AdditionalDependencies="Wbemuuid.lib" 
     155        AdditionalDependencies="Mstask.lib" 
    156156        OutputFile="../../Debug/modules/$(ProjectName).dll" 
    157157        LinkIncremental="2" 
     
    192192      Name="Release|Win32" 
    193193      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    194       IntermediateDirectory="$(ConfigurationName)" 
     194      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    195195      ConfigurationType="2" 
    196196      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    273273      Name="Release|x64" 
    274274      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    275       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     275      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    276276      ConfigurationType="2" 
    277277      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    315315      <Tool 
    316316        Name="VCLinkerTool" 
    317         AdditionalDependencies="Wbemuuid.lib" 
     317        AdditionalDependencies="Mstask.lib" 
    318318        OutputFile="../../Release/modules/$(ProjectName).dll" 
    319319        LinkIncremental="1" 
     
    478478      <Tool 
    479479        Name="VCLinkerTool" 
    480         AdditionalDependencies="Wbemuuid.lib" 
     480        AdditionalDependencies="Mstask.lib" 
    481481        OutputFile="../../Dist/modules/$(ProjectName).dll" 
    482482        LinkIncremental="1" 
     
    801801      <Tool 
    802802        Name="VCLinkerTool" 
    803         AdditionalDependencies="Wbemuuid.lib" 
     803        AdditionalDependencies="Mstask.lib" 
    804804        OutputFile="../../Debug/modules/$(ProjectName).dll" 
    805805        LinkIncremental="2" 
  • modules/CheckWMI/CheckWMI-2005.vcproj

    r3f569d3 rc0522cd  
    192192      Name="Release|Win32" 
    193193      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    194       IntermediateDirectory="$(ConfigurationName)" 
     194      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    195195      ConfigurationType="2" 
    196196      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    273273      Name="Release|x64" 
    274274      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    275       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     275      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    276276      ConfigurationType="2" 
    277277      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/FileLogger/FileLogger-2005.vcproj

    r3f569d3 rc0522cd  
    2525      Name="Release|Win32" 
    2626      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    27       IntermediateDirectory="$(ConfigurationName)" 
     27      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    2828      ConfigurationType="2" 
    2929      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    104104      Name="Release|x64" 
    105105      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    106       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     106      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    107107      ConfigurationType="2" 
    108108      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/LUAScript/LUAScript-2005.vcproj

    r99b84bf rc0522cd  
    192192      Name="Release|Win32" 
    193193      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    194       IntermediateDirectory="$(ConfigurationName)" 
     194      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    195195      ConfigurationType="2" 
    196196      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    273273      Name="Release|x64" 
    274274      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    275       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     275      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    276276      ConfigurationType="2" 
    277277      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/NRPEClient/NRPEClient-2005.vcproj

    r394f7a1 rc0522cd  
    193193      Name="Release|Win32" 
    194194      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    195       IntermediateDirectory="$(ConfigurationName)" 
     195      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    196196      ConfigurationType="2" 
    197197      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    274274      Name="Release|x64" 
    275275      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    276       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     276      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    277277      ConfigurationType="2" 
    278278      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/NRPEListener/NRPEListener-2005.vcproj

    r394f7a1 rc0522cd  
    193193      Name="Release|Win32" 
    194194      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    195       IntermediateDirectory="$(ConfigurationName)" 
     195      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    196196      ConfigurationType="2" 
    197197      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    274274      Name="Release|x64" 
    275275      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    276       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     276      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    277277      ConfigurationType="2" 
    278278      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/NSCAAgent/NSCAAgent-2005.vcproj

    r1d84e57 rc0522cd  
    191191    <Configuration 
    192192      Name="Release|Win32" 
    193       OutputDirectory="$(ConfigurationName)" 
    194       IntermediateDirectory="$(ConfigurationName)" 
     193      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     194      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    195195      ConfigurationType="2" 
    196196      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    272272    <Configuration 
    273273      Name="Release|x64" 
    274       OutputDirectory="$(PlatformName)\$(ConfigurationName)" 
    275       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     274      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     275      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    276276      ConfigurationType="2" 
    277277      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/NSClientListener/NSClientListener-2005.vcproj

    r3f569d3 rc0522cd  
    190190      Name="Release|Win32" 
    191191      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    192       IntermediateDirectory="$(ConfigurationName)" 
     192      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    193193      ConfigurationType="2" 
    194194      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    270270      Name="Release|x64" 
    271271      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    272       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     272      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    273273      ConfigurationType="2" 
    274274      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/RemoteConfiguration/RemoteConfiguration-2005.vcproj

    r3f569d3 rc0522cd  
    188188      Name="Release|Win32" 
    189189      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    190       IntermediateDirectory="$(ConfigurationName)" 
     190      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    191191      ConfigurationType="2" 
    192192      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    267267      Name="Release|x64" 
    268268      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    269       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     269      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    270270      ConfigurationType="2" 
    271271      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/SysTray/SysTray-2005.vcproj

    r6b690bf rc0522cd  
    2525      Name="Release|Win32" 
    2626      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    27       IntermediateDirectory="$(ConfigurationName)" 
     27      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    2828      ConfigurationType="2" 
    2929      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    104104      Name="Release|x64" 
    105105      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    106       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     106      IntermediateDirectory="tmp\$(PlatformName)\$(ConfigurationName)" 
    107107      ConfigurationType="2" 
    108108      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
  • modules/SysTray/SysTray.cpp

    r846bbe4 rc0522cd  
    2424#include <ServiceCmd.h> 
    2525#include <config.h> 
     26#include <Winwlx.h> 
     27#include <sysinfo.h> 
    2628 
    2729SysTray gSysTray; 
     
    3537SysTray::SysTray() : icon(_T("SysTray")) {} 
    3638SysTray::~SysTray() {} 
     39 
     40 
     41void SysTray::show() { 
     42  icon.createThread(); 
     43} 
    3744bool SysTray::loadModule() { 
    38   try { 
    39     if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 
     45  if (systemInfo::isBelowXP(systemInfo::getOSVersion())) { 
     46    try { 
     47      if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 
     48        NSC_LOG_ERROR(_T("SysTray is not installed (or it cannot interact with the desktop) SysTray won't be loaded. Run ") SZAPPNAME _T(" SysTray install to change this.")); 
     49        return true; 
     50      } 
     51    } catch (serviceControll::SCException e) { 
    4052      NSC_LOG_ERROR(_T("SysTray is not installed (or it cannot interact with the desktop) SysTray won't be loaded. Run ") SZAPPNAME _T(" SysTray install to change this.")); 
    4153      return true; 
    4254    } 
    43   } catch (serviceControll::SCException e) { 
    44     NSC_LOG_ERROR(_T("SysTray is not installed (or it cannot interact with the desktop) SysTray won't be loaded. Run ") SZAPPNAME _T(" SysTray install to change this.")); 
    45     return true; 
     55    show(); 
     56  } else { 
     57    NSC_LOG_ERROR(_T("SysTray module is not used on windows XP and above (so you can remove it).")); 
    4658  } 
    47   icon.createThread(); 
    4859  return true; 
    4960} 
    50 bool SysTray::unloadModule() { 
     61void SysTray::hide() { 
    5162  if (!icon.exitThread(20000)) { 
    5263    std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl; 
    5364    NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result...")); 
    54     return false; 
     65  } 
     66} 
     67bool SysTray::unloadModule() { 
     68  if (systemInfo::isBelowXP(systemInfo::getOSVersion())) { 
     69    hide(); 
    5570  } 
    5671  return true; 
     
    6176    try { 
    6277      serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS); 
    63       NSC_LOG_MESSAGE_STD(_T(MODULE_NAME) _T(" is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set.")); 
     78      std::wcout << _T(MODULE_NAME) << _T(" is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set.") << std::endl; 
    6479    } catch (const serviceControll::SCException& e) { 
    65       NSC_LOG_ERROR_STD(_T("Could not modify service: ") + e.error_); 
     80      std::wcerr << _T("Could not modify service: ") << e.error_ << std::endl; 
     81      return -1; 
     82    } catch (...) { 
     83      std::wcerr << _T("Could not modify service: Unknown error!") << std::endl; 
    6684      return -1; 
    6785    } 
     
    6987    try { 
    7088      serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS); 
    71       NSC_LOG_MESSAGE_STD(_T(MODULE_NAME) _T(" is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset.")); 
     89      std::wcout << _T(" is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset.") << std::endl; 
    7290    } catch (const serviceControll::SCException& e) { 
    73       NSC_LOG_ERROR_STD(_T("Could not modify service: ") + e.error_); 
     91      std::wcerr << _T("Could not modify service: ") << e.error_ << std::endl; 
     92      return -1; 
     93    } catch (...) { 
     94      std::wcerr << _T("Could not modify service: Unknown error!") << std::endl; 
    7495      return -1; 
    7596    } 
    7697  } else { 
    77     NSC_LOG_ERROR_STD(_T("Undefined command, usage: install or uninstall")); 
     98    std::wcerr << _T("Undefined command, usage: install or uninstall") << std::endl; 
    7899    return -1; 
    79100  } 
     
    120141} 
    121142 
    122  
    123  
    124  
     143extern void ShowIcon() { 
     144  gSysTray.show(); 
     145} 
     146extern void HideIcon() { 
     147  gSysTray.hide(); 
     148} 
    125149NSC_WRAPPERS_MAIN_DEF(gSysTray); 
    126150NSC_WRAPPERS_HANDLE_MSG_DEF(gSysTray); 
  • modules/SysTray/SysTray.def

    r6817602 rc0522cd  
    1313  NSGetModuleDescription 
    1414  NSCommandLineExec 
     15  ShowIcon 
     16  HideIcon 
  • modules/SysTray/SysTray.h

    rb5ef837 rc0522cd  
    2626NSC_WRAPPERS_MAIN(); 
    2727NSC_WRAPPERS_CLI(); 
     28 
    2829 
    2930 
     
    5657  bool unloadModule(); 
    5758  void setLogWindow(HWND hWnd); 
     59  void show(); 
     60  void hide(); 
    5861 
    5962  std::wstring getModuleName() { 
  • modules/SysTray/SysTray.rc

    rde8ef76 rc0522cd  
    9595    POPUP "POPUP" 
    9696    BEGIN 
    97         MENUITEM "NSClient++",                  ID_POPUP_NSCLIENT, INACTIVE 
     97        MENUITEM "NSClient++",            ID_POPUP_NSCLIENT, INACTIVE 
    9898        MENUITEM SEPARATOR 
    99         MENUITEM "Inject Command",              ID_POPUP_INJECTCOMMAND 
    100         MENUITEM "Stop Service",                ID_POPUP_STOPSERVICE 
     99        MENUITEM "Run &Command",          ID_POPUP_INJECTCOMMAND 
     100        MENUITEM "Show &Log",             ID_POPUP_SHOWLOG 
    101101        MENUITEM SEPARATOR 
    102         MENUITEM "Show Log",                    ID_POPUP_SHOWLOG 
     102        MENUITEM "&Close",                ID_POPUP_STOPSERVICE 
    103103    END 
    104104END 
     
    225225///////////////////////////////////////////////////////////////////////////// 
    226226#endif    // not APSTUDIO_INVOKED 
    227  
  • modules/SysTray/TrayIcon.cpp

    r846bbe4 rc0522cd  
    5050  if (fnChangeWindowMessageFilter == NULL) 
    5151    fnChangeWindowMessageFilter = (LPFN_CHANGEWINDOWMESSAGEFILTER)GetProcAddress(GetModuleHandle(TEXT("user32")),"ChangeWindowMessageFilter"); 
    52   if (fnChangeWindowMessageFilter == NULL) 
     52  if (fnChangeWindowMessageFilter == NULL) { 
     53    NSC_DEBUG_MSG(_T("Failed to load: ChangeWindowMessageFilter aparently we are not on Vista...")); 
    5354    return true; 
     55  } 
     56  NSC_DEBUG_MSG(_T("Chaning window message filters...")); 
    5457  return fnChangeWindowMessageFilter(message,what); 
    5558} 
    5659 
     60void test() { 
     61/* error  
     62WTSQueryUserToken(dwSessionId, &hToken); 
     63DuplicateTokenEx(hTokenNew,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hTokenDup); 
     64*/ 
     65/* 
     66  HANDLE hToken = NULL, hTokenDup = NULL; 
     67  HMODULE  hmod = LoadLibrary("kernel32.dll"); 
     68  WTSGETACTIVECONSOLESESSIONID lpfnWTSGetActiveConsoleSessionId = (WTSGETACTIVECONSOLESESSIONID)GetProcAddress(hmod,"WTSGetActiveConsoleSessionId");  
     69  DWORD dwSessionId = lpfnWTSGetActiveConsoleSessionId(); 
     70  WTSQueryUserToken(dwSessionId, &hToken); 
     71  //DuplicateTokenEx(hTokenNew,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hTokenDup); 
     72  // 
     73  WriteToLog("Calling lpfnCreateEnvironmentBlock"); 
     74  ZeroMemory( &si, sizeof( STARTUPINFO ) ); 
     75  si.cb = sizeof( STARTUPINFO ); 
     76  si.lpDesktop = "winsta0\\default"; 
     77 
     78 
     79  LPVOID  pEnv = NULL; 
     80  DWORD dwCreationFlag = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE; 
     81  HMODULE hModule = LoadLibrary("Userenv.dll"); 
     82  if(hModule ) 
     83  { 
     84    LPFN_CreateEnvironmentBlock lpfnCreateEnvironmentBlock = (LPFN_CreateEnvironmentBlock)GetProcAddress( hModule, "CreateEnvironmentBlock" ); 
     85    if( lpfnCreateEnvironmentBlock != NULL ) 
     86    { 
     87      if(lpfnCreateEnvironmentBlock(&pEnv, hTokenDup, FALSE)) 
     88      { 
     89        WriteToLog("CreateEnvironmentBlock Ok"); 
     90        dwCreationFlag |= CREATE_UNICODE_ENVIRONMENT;     
     91      } 
     92      else 
     93      { 
     94        pEnv = NULL; 
     95      } 
     96    } 
     97  } 
     98  // 
     99  ZeroMemory( &pi,sizeof(pi)); 
     100 
     101  if ( !CreateProcessAsUser( 
     102    hTokenDup, 
     103    NULL, 
     104    ( char * )pszCmd,   
     105    NULL, 
     106    NULL, 
     107    FALSE, 
     108    dwCreationFlag, 
     109    pEnv, 
     110    NULL, 
     111    &si, 
     112    &pi 
     113    ) ) 
     114  { 
     115 
     116    goto RESTORE; 
     117  }  
     118*/ 
     119 
     120} 
    57121 
    58122void IconWidget_::createDialog(void) { 
    59   ChangeWindowMessageFilter() 
    60123  hDlgWnd = ::CreateDialog(NSCModuleWrapper::getModule(),MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 
    61124 
     
    64127    NSC_LOG_ERROR_STD(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 
    65128  } 
    66   ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD); 
     129  if (!ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
     130    NSC_LOG_ERROR_STD(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 
     131  } 
    67132 
    68133  MSG Msg; 
     
    319384      switch (cmd) { 
    320385      case ID_POPUP_STOPSERVICE: 
    321         NSCModuleHelper::StopService(); 
     386        NSCModuleHelper::Exit(); 
    322387        break; 
    323388      case ID_POPUP_INJECTCOMMAND: 
Note: See TracChangeset for help on using the changeset viewer.