Changeset 739db5a in nscp for modules/SysTray


Ignore:
Timestamp:
09/27/08 19:06:35 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
37e6081
Parents:
9567d4b
Message:

First attempt at merging stable changes over to here (probably needs more work, but compiles and starts...)

Location:
modules/SysTray
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • modules/SysTray/SysTray-2005.vcproj

    r6b690bf r739db5a  
    2525      Name="Release|Win32" 
    2626      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    27       IntermediateDirectory="$(ConfigurationName)" 
     27      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    2828      ConfigurationType="2" 
    2929      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    6666      <Tool 
    6767        Name="VCLinkerTool" 
    68         OutputFile="../../Release/modules/$(ProjectName).dll" 
     68        OutputFile="$(OutDir)\$(ProjectName).dll" 
    6969        LinkIncremental="1" 
    7070        ModuleDefinitionFile="SysTray.def" 
     
    104104      Name="Release|x64" 
    105105      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    106       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     106      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    107107      ConfigurationType="2" 
    108108      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    146146      <Tool 
    147147        Name="VCLinkerTool" 
    148         OutputFile="../../Release/modules/$(ProjectName).dll" 
     148        OutputFile="$(OutDir)\$(ProjectName).dll" 
    149149        LinkIncremental="1" 
    150150        ModuleDefinitionFile="SysTray.def" 
     
    183183    <Configuration 
    184184      Name="Debug|Win32" 
    185       OutputDirectory="$(ConfigurationName)" 
    186       IntermediateDirectory="$(ConfigurationName)" 
     185      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     186      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    187187      ConfigurationType="2" 
    188188      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    228228      <Tool 
    229229        Name="VCLinkerTool" 
    230         OutputFile="../../Debug/modules/$(ProjectName).dll" 
     230        OutputFile="$(OutDir)\$(ProjectName).dll" 
    231231        ModuleDefinitionFile="SysTray.def" 
    232232        GenerateDebugInformation="true" 
     
    261261    <Configuration 
    262262      Name="Debug|x64" 
    263       OutputDirectory="$(PlatformName)\$(ConfigurationName)" 
    264       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     263      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     264      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    265265      ConfigurationType="2" 
    266266      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    307307      <Tool 
    308308        Name="VCLinkerTool" 
    309         OutputFile="../../Debug/modules/$(ProjectName).dll" 
     309        OutputFile="$(OutDir)\$(ProjectName).dll" 
    310310        ModuleDefinitionFile="SysTray.def" 
    311311        GenerateDebugInformation="true" 
     
    340340    <Configuration 
    341341      Name="Distribution|Win32" 
    342       OutputDirectory="$(ConfigurationName)" 
    343       IntermediateDirectory="$(ConfigurationName)" 
     342      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     343      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    344344      ConfigurationType="2" 
    345345      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    382382      <Tool 
    383383        Name="VCLinkerTool" 
    384         OutputFile="../../Dist/modules/$(ProjectName).dll" 
     384        OutputFile="$(OutDir)\$(ProjectName).dll" 
    385385        LinkIncremental="1" 
    386386        ModuleDefinitionFile="SysTray.def" 
     
    419419    <Configuration 
    420420      Name="Distribution|x64" 
    421       OutputDirectory="$(PlatformName)\$(ConfigurationName)" 
    422       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     421      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     422      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    423423      ConfigurationType="2" 
    424424      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    462462      <Tool 
    463463        Name="VCLinkerTool" 
    464         OutputFile="../../Dist/modules/$(ProjectName).dll" 
     464        OutputFile="$(OutDir)\$(ProjectName).dll" 
    465465        LinkIncremental="1" 
    466466        ModuleDefinitionFile="SysTray.def" 
     
    500500      Name="Nightly|Win32" 
    501501      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    502       IntermediateDirectory="$(ConfigurationName)" 
     502      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    503503      ConfigurationType="2" 
    504504      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    539539      <Tool 
    540540        Name="VCLinkerTool" 
     541        OutputFile="$(OutDir)\$(ProjectName).dll" 
    541542        LinkIncremental="1" 
    542543        ModuleDefinitionFile="SysTray.def" 
     
    575576      Name="Nightly|x64" 
    576577      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
    577       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     578      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    578579      ConfigurationType="2" 
    579580      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    615616      <Tool 
    616617        Name="VCLinkerTool" 
     618        OutputFile="$(OutDir)\$(ProjectName).dll" 
    617619        LinkIncremental="1" 
    618620        ModuleDefinitionFile="SysTray.def" 
     
    650652    <Configuration 
    651653      Name="Debug-MemCheck|Win32" 
    652       OutputDirectory="$(ConfigurationName)" 
    653       IntermediateDirectory="$(ConfigurationName)" 
     654      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     655      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    654656      ConfigurationType="2" 
    655657      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    695697      <Tool 
    696698        Name="VCLinkerTool" 
    697         OutputFile="../../Debug/modules/$(ProjectName).dll" 
     699        OutputFile="$(OutDir)\$(ProjectName).dll" 
    698700        ModuleDefinitionFile="SysTray.def" 
    699701        GenerateDebugInformation="true" 
     
    728730    <Configuration 
    729731      Name="Debug-MemCheck|x64" 
    730       OutputDirectory="$(PlatformName)\$(ConfigurationName)" 
    731       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)" 
     732      OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)\modules" 
     733      IntermediateDirectory="$(SolutionDir)\tmp\$(PlatformName)\$(ConfigurationName)\$(ProjectName)" 
    732734      ConfigurationType="2" 
    733735      InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops" 
     
    774776      <Tool 
    775777        Name="VCLinkerTool" 
    776         OutputFile="../../Debug/modules/$(ProjectName).dll" 
     778        OutputFile="$(OutDir)\$(ProjectName).dll" 
    777779        ModuleDefinitionFile="SysTray.def" 
    778780        GenerateDebugInformation="true" 
  • modules/SysTray/SysTray.cpp

    r9567d4b r739db5a  
    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} 
     44 
    3745bool SysTray::loadModule(NSCAPI::moduleLoadMode mode) { 
    3846  if (mode == NSCAPI::normalStart) { 
     47    if (SETTINGS_GET_BOOL(settings_def::SHARED_SESSION)) { 
     48      NSC_LOG_ERROR(_T("You have enabled shared session, systray module will not load...")); 
     49      return true; 
     50    } 
    3951    try { 
    4052      if ((serviceControll::GetServiceType(SZSERVICENAME)&SERVICE_INTERACTIVE_PROCESS)!=SERVICE_INTERACTIVE_PROCESS) { 
     
    4658      return true; 
    4759    } 
    48     icon.createThread(); 
     60    show(); 
    4961  } 
    5062  return true; 
    5163} 
    52 bool SysTray::unloadModule() { 
     64void SysTray::hide() { 
    5365  if (!icon.exitThread(20000)) { 
    5466    std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl; 
    5567    NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result...")); 
    56     return false; 
     68  } 
     69} 
     70bool SysTray::unloadModule() { 
     71  if (systemInfo::isBelowXP(systemInfo::getOSVersion())) { 
     72    hide(); 
    5773  } 
    5874  return true; 
     
    6379    try { 
    6480      serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS); 
    65       NSC_LOG_MESSAGE_STD(_T(MODULE_NAME) _T(" is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set.")); 
     81      std::wcout << _T(MODULE_NAME) << _T(" is now able to run as the SERVICE_INTERACTIVE_PROCESS flag has been set.") << std::endl; 
    6682    } catch (const serviceControll::SCException& e) { 
    67       NSC_LOG_ERROR_STD(_T("Could not modify service: ") + e.error_); 
     83      std::wcerr << _T("Could not modify service: ") << e.error_ << std::endl; 
     84      return -1; 
     85    } catch (...) { 
     86      std::wcerr << _T("Could not modify service: Unknown error!") << std::endl; 
    6887      return -1; 
    6988    } 
     
    7190    try { 
    7291      serviceControll::ModifyServiceType(SZSERVICENAME, SERVICE_WIN32_OWN_PROCESS); 
    73       NSC_LOG_MESSAGE_STD(_T(MODULE_NAME) _T(" is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset.")); 
     92      std::wcout << _T(" is now not able to run as the SERVICE_INTERACTIVE_PROCESS flag has been reset.") << std::endl; 
    7493    } catch (const serviceControll::SCException& e) { 
    75       NSC_LOG_ERROR_STD(_T("Could not modify service: ") + e.error_); 
     94      std::wcerr << _T("Could not modify service: ") << e.error_ << std::endl; 
     95      return -1; 
     96    } catch (...) { 
     97      std::wcerr << _T("Could not modify service: Unknown error!") << std::endl; 
    7698      return -1; 
    7799    } 
    78100  } else { 
    79     NSC_LOG_ERROR_STD(_T("Undefined command, usage: install or uninstall")); 
     101    std::wcerr << _T("Undefined command, usage: install or uninstall") << std::endl; 
    80102    return -1; 
    81103  } 
     
    108130      hWnd = hLogWnd; 
    109131    } else { 
    110       std::cout << "Damnit!!!" << std::endl; 
    111132      NSC_LOG_ERROR_STD(_T("Failed to get mutex in logger, message discarded")); 
    112133    } 
     
    123144} 
    124145 
    125  
    126  
    127  
     146extern void ShowIcon() { 
     147  gSysTray.show(); 
     148} 
     149extern void HideIcon() { 
     150  gSysTray.hide(); 
     151} 
    128152NSC_WRAPPERS_MAIN_DEF(gSysTray); 
    129153NSC_WRAPPERS_HANDLE_MSG_DEF(gSysTray); 
  • modules/SysTray/SysTray.def

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

    r9567d4b r739db5a  
    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 r739db5a  
    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

    r6d3bbc1 r739db5a  
    3939} 
    4040 
     41#ifdef WINVER < 0x0600 
     42#define MSGFLT_ADD 1 
     43#define MSGFLT_REMOVE 2 
     44typedef BOOL (WINAPI *LPFN_CHANGEWINDOWMESSAGEFILTER) (UINT, DWORD); 
     45#endif 
     46 
     47LPFN_CHANGEWINDOWMESSAGEFILTER fnChangeWindowMessageFilter = NULL; 
     48BOOL ChangeWindowMessageFilter_(UINT message, DWORD what) 
     49{ 
     50  if (fnChangeWindowMessageFilter == NULL) 
     51    fnChangeWindowMessageFilter = (LPFN_CHANGEWINDOWMESSAGEFILTER)GetProcAddress(GetModuleHandle(TEXT("user32")),"ChangeWindowMessageFilter"); 
     52  if (fnChangeWindowMessageFilter == NULL) { 
     53    NSC_DEBUG_MSG(_T("Failed to load: ChangeWindowMessageFilter aparently we are not on Vista...")); 
     54    return true; 
     55  } 
     56  NSC_DEBUG_MSG(_T("Chaning window message filters...")); 
     57  return fnChangeWindowMessageFilter(message,what); 
     58} 
     59 
     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} 
    41121 
    42122void IconWidget_::createDialog(void) { 
     
    46126  if (UDM_TASKBARCREATED == 0) { 
    47127    NSC_LOG_ERROR_STD(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 
     128  } 
     129  if (!ChangeWindowMessageFilter_(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
     130    NSC_LOG_ERROR_STD(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 
    48131  } 
    49132 
     
    301384      switch (cmd) { 
    302385      case ID_POPUP_STOPSERVICE: 
    303         NSCModuleHelper::StopService(); 
     386        NSCModuleHelper::Exit(); 
    304387        break; 
    305388      case ID_POPUP_INJECTCOMMAND: 
Note: See TracChangeset for help on using the changeset viewer.