Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1244 lines
39 KiB

  1. // emshell.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "emshell.h"
  5. #include "MainFrm.h"
  6. #include "emshellDoc.h"
  7. #include "emshellView.h"
  8. #include "genparse.h"
  9. #include <atlbase.h>
  10. #include <comdef.h>
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. extern BSTR CopyBSTR( LPBYTE pb, ULONG cb );
  17. extern const TCHAR* gtcFileOpenFlags;
  18. const TCHAR* gtcPollSessionsFreq = _T("PollSessionsFreq");
  19. const TCHAR* gtcWindowHeight = _T("WindowHeight");
  20. const TCHAR* gtcWindowWidth = _T("WindowWidth");
  21. const TCHAR* gtcRecursive = _T("Recursive");
  22. const TCHAR* gtcCommandSet = _T("CommandSet");
  23. const TCHAR* gtcMiniDump = _T("MiniDump");
  24. const TCHAR* gtcUserDump = _T("UserDump");
  25. const TCHAR* gtcNotifyAdmin = _T("NotifyAdmin");
  26. const TCHAR* gtcMsinfoDump = _T("MsinfoDump");
  27. const TCHAR* gtcAdminName = _T("AdminName");
  28. const TCHAR* gtcAltSymbolPath = _T("AltSymbolPath");
  29. const TCHAR* gtcSelectedCommandSet = _T("SelectedCommandSet");
  30. const TCHAR* gtcPassword = _T("Password");
  31. const TCHAR* gtcPort = _T("Port");
  32. const TCHAR* gtcUsername = _T("Username");
  33. const TCHAR* gtcShowMSInfoDlg = _T("ShowMSInfoDlg");
  34. const TCHAR* gtcEmDir = _T("emdir");
  35. const TCHAR* gtcNoDebugProcesses = _T("NoDebugProcesses");
  36. const TCHAR* gtcWildCardNoDebugServices = _T("WildCardNoDebugServices");
  37. const TCHAR* gtcNoDebugServices = _T("NoDebugServices");
  38. const TCHAR* gtcNoDbgDefSvcList = _T("EMSVC;RPCSS;IISADMIN");
  39. const TCHAR* gtcNoDbgDefProcList = _T("EM.EXE;WINLOGON.EXE;EXPLORER.EXE;CSRSS.EXE;SMSS.EXE");
  40. const TCHAR* gtcWldCrdDefList = _T("LSASS;SERVICES ;SVCHOST;SERVICES.EXE");
  41. const TCHAR* gtcDefPassword = _T("microsoftvi");
  42. const TCHAR* gtcDefPort = _T("70");
  43. const TCHAR* gtcDefUsername = _T("em");
  44. const TCHAR* gtcDefAltSymbolPath = _T("");
  45. const TCHAR* gtcDefSelectedCommandSet = _T("");
  46. const TCHAR* gtcDefAdminName = _T("");
  47. const DWORD gnDefWindowWidth = 240;
  48. const DWORD gnDefWindowHeight = 320;
  49. const DWORD gnDefSessionRefreshRate = 30;
  50. const DWORD gnDefUserDumpFlag = 0;
  51. const DWORD gnDefShowMSInfoDlgFlag = 1;
  52. const DWORD gnDefRecursiveFlag = 0;
  53. const DWORD gnDefNotifyAdminFlag = 0;
  54. const DWORD gnDefMSInfoDumpFlag = 0;
  55. const DWORD gnDefMiniDumpFlag = 1;
  56. const DWORD gnDefCommandSetFlag = 0;
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CEmshellApp
  59. BEGIN_MESSAGE_MAP(CEmshellApp, CWinApp)
  60. //{{AFX_MSG_MAP(CEmshellApp)
  61. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  62. //}}AFX_MSG_MAP
  63. // Standard file based document commands
  64. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  65. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  66. // Standard print setup command
  67. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CEmshellApp construction
  71. CEmshellApp::CEmshellApp()
  72. {
  73. // TODO: add construction code here,
  74. // Place all significant initialization in InitInstance
  75. m_dwSessionRefreshRate = gnDefSessionRefreshRate;
  76. m_dwWindowWidth = gnDefWindowWidth;
  77. m_dwWindowHeight = gnDefWindowHeight;
  78. m_dwRecursive = gnDefRecursiveFlag;
  79. m_dwMiniDump = gnDefMiniDumpFlag;
  80. m_dwUserDump = gnDefUserDumpFlag;
  81. m_dwMsinfoDump = gnDefMSInfoDumpFlag;
  82. m_dwShowMSInfoDlg = gnDefShowMSInfoDlgFlag;
  83. m_SessionSettings.dwCommandSet = gnDefCommandSetFlag;
  84. m_SessionSettings.dwNotifyAdmin = gnDefNotifyAdminFlag;
  85. m_SessionSettings.dwProduceMiniDump = gnDefMiniDumpFlag;
  86. m_SessionSettings.dwProduceUserDump = gnDefUserDumpFlag;
  87. m_SessionSettings.dwRecursiveMode = gnDefRecursiveFlag;
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // The one and only CEmshellApp object
  91. CEmshellApp theApp;
  92. /////////////////////////////////////////////////////////////////////////////
  93. #ifdef _DEBUG
  94. void
  95. TestCommandLine
  96. (
  97. LPCTSTR pszCmdLine
  98. )
  99. {
  100. CGenCommandLine parser;
  101. CString sText;
  102. TCHAR *szCmdLines[] = {
  103. L"-ntx",
  104. L"-ntx -pid 45 -mfc, -ntx -vc6 -lib",
  105. L"-server /tcp /port=325",
  106. NULL
  107. };
  108. for (int i=0 ; szCmdLines[i] ; i++) {
  109. parser.Initialize( szCmdLines[i] );
  110. OutputDebugString ( szCmdLines[i] );
  111. OutputDebugString ( L"\n" );
  112. while ( parser.GetNext() != NULL ) {
  113. LPCTSTR pszToken = parser.GetToken();
  114. LPCTSTR pszValue = parser.GetValue();
  115. sText.Format( TEXT("Token:%s, Value:%s\n"), (pszToken), (pszValue) );
  116. OutputDebugString ( sText );
  117. }
  118. OutputDebugString ( L"\n" );
  119. }
  120. }
  121. #endif // #ifdef _DEBUG
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CEmshellApp initialization
  124. BOOL CEmshellApp::InitInstance()
  125. {
  126. #ifdef _AFXDLL
  127. Enable3dControls(); // Call this when using MFC in a shared DLL
  128. #else
  129. Enable3dControlsStatic(); // Call this when linking to MFC statically
  130. #endif
  131. #ifdef _DEBUG
  132. TestCommandLine(GetCommandLine());
  133. #endif
  134. //CoInitializeEx(NULL, COINIT_MULTITHREADED);
  135. CoInitialize(NULL);
  136. //CoInitializeEx( NULL, COINIT_MULTITHREADED );
  137. // ::AfxOleInit();
  138. if ( !InitEmshell() ) {
  139. return false;
  140. }
  141. if(ReadDataFromRegistry() != ERROR_SUCCESS && CreateEmShellRegEntries() != ERROR_SUCCESS ) {
  142. MessageBox( NULL, _T("Registry entry not found.\nPlease re-install the application"), _T("Registry corrupted"), MB_OK);
  143. return FALSE;
  144. }
  145. //Get the path to CDB from the registry
  146. GetCDBPathFromRegistry();
  147. //Synchronize the session dlg data with the registry
  148. UpdateSessionData();
  149. return TRUE;
  150. }
  151. /////////////////////////////////////////////////////////////////////////////
  152. bool CEmshellApp::InitEmshell
  153. (
  154. int nCmdShow /* = SW_SHOW */
  155. )
  156. {
  157. CSingleDocTemplate* pDocTemplate;
  158. pDocTemplate = new CSingleDocTemplate(
  159. IDR_MAINFRAME,
  160. RUNTIME_CLASS(CEmshellDoc),
  161. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  162. RUNTIME_CLASS(CEmshellView));
  163. AddDocTemplate(pDocTemplate);
  164. return ( AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL) > 0);
  165. }
  166. /////////////////////////////////////////////////////////////////////////////
  167. // CAboutDlg dialog used for App About
  168. class CAboutDlg : public CDialog
  169. {
  170. public:
  171. CAboutDlg();
  172. // Dialog Data
  173. //{{AFX_DATA(CAboutDlg)
  174. enum { IDD = IDD_ABOUTBOX };
  175. //}}AFX_DATA
  176. // ClassWizard generated virtual function overrides
  177. //{{AFX_VIRTUAL(CAboutDlg)
  178. protected:
  179. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  180. //}}AFX_VIRTUAL
  181. // Implementation
  182. protected:
  183. //{{AFX_MSG(CAboutDlg)
  184. virtual void OnOK();
  185. //}}AFX_MSG
  186. DECLARE_MESSAGE_MAP()
  187. };
  188. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  189. {
  190. //{{AFX_DATA_INIT(CAboutDlg)
  191. //}}AFX_DATA_INIT
  192. }
  193. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  194. {
  195. CDialog::DoDataExchange(pDX);
  196. //{{AFX_DATA_MAP(CAboutDlg)
  197. //}}AFX_DATA_MAP
  198. }
  199. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  200. //{{AFX_MSG_MAP(CAboutDlg)
  201. //}}AFX_MSG_MAP
  202. END_MESSAGE_MAP()
  203. // App command to run the dialog
  204. void CEmshellApp::OnAppAbout()
  205. {
  206. CAboutDlg aboutDlg;
  207. aboutDlg.DoModal();
  208. }
  209. /////////////////////////////////////////////////////////////////////////////
  210. // CEmshellApp message handlers
  211. void CAboutDlg::OnOK()
  212. {
  213. // TODO: Add extra validation here
  214. CDialog::OnOK();
  215. }
  216. int CEmshellApp::ExitInstance()
  217. {
  218. //Uninitialize the COM services
  219. //Taken out since were now using AfxOleInit
  220. CoUninitialize();
  221. SetEmShellRegOptions( TRUE );
  222. return CWinApp::ExitInstance();
  223. }
  224. int CEmshellApp::DisplayErrMsgFromHR(HRESULT hr, UINT nType)
  225. {
  226. void* pMsgBuf;
  227. DWORD dwSize = 0;
  228. int nRetVal = 0;
  229. CString strCaption;
  230. CString strTemp;
  231. CString strMessage;
  232. do {
  233. dwSize = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  234. NULL,
  235. hr,
  236. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  237. (LPTSTR) &pMsgBuf,
  238. 0,
  239. NULL) ;
  240. if (dwSize == 0) break;
  241. strMessage = (LPTSTR) pMsgBuf;
  242. strMessage += "\n";
  243. strCaption.LoadString(IDS_ERRORMSG);
  244. //If we know the message, let's give them a description of what's going on
  245. switch( LOWORD( hr ) ) {
  246. case RPC_S_SERVER_UNAVAILABLE:
  247. strMessage += "\n\n";
  248. //Notify the user that the connection has failed.
  249. strTemp.LoadString( IDS_ERROR_CONNECTION_TERMINATED );
  250. strMessage += strTemp;
  251. break;
  252. }
  253. nRetVal = MessageBox(::AfxGetMainWnd()->m_hWnd, strMessage, strCaption, nType);
  254. //Release the buffer given to us from FormatMessage()
  255. LocalFree(pMsgBuf);
  256. } while (FALSE);
  257. return nRetVal;
  258. }
  259. int CEmshellApp::DisplayErrMsgFromString(CString strMessage, UINT nType)
  260. {
  261. int nRetVal = 0;
  262. CString strCaption;
  263. strCaption.LoadString(IDS_ERRORMSG);
  264. nRetVal = MessageBox(::AfxGetMainWnd()->m_hWnd, strMessage, strCaption, nType);
  265. return nRetVal;
  266. }
  267. void CEmshellApp::GetEmObjectTypeString(LONG lType, CString &csStatusStr)
  268. {
  269. int nId = -1;
  270. csStatusStr = _T("");
  271. switch(lType)
  272. {
  273. case EMOBJ_SERVICE:
  274. nId = IDS_EMOBJECT_TYPE_SERVICE;
  275. break;
  276. case EMOBJ_PROCESS:
  277. nId = IDS_EMOBJECT_TYPE_PROCESS;
  278. break;
  279. case EMOBJ_LOGFILE:
  280. nId = IDS_EMOBJECT_TYPE_LOGFILE;
  281. break;
  282. case EMOBJ_MINIDUMP:
  283. nId = IDS_EMOBJECT_TYPE_MINIDUMP;
  284. break;
  285. case EMOBJ_USERDUMP:
  286. nId = IDS_EMOBJECT_TYPE_USERDUMP;
  287. break;
  288. case EMOBJ_UNKNOWNOBJECT:
  289. nId = IDS_EMOBJECT_TYPE_UNKNOWNOBJECT;
  290. break;
  291. default:
  292. break;
  293. }
  294. csStatusStr.LoadString(nId);
  295. }
  296. PEmObject CEmshellApp::AllocEmObject()
  297. {
  298. PEmObject pEmObject = NULL;
  299. pEmObject = new EmObject;
  300. if (pEmObject == NULL) DisplayErrMsgFromHR(E_OUTOFMEMORY);
  301. return pEmObject;
  302. }
  303. void CEmshellApp::DeAllocEmObject(PEmObject pEmObj)
  304. {
  305. _ASSERTE(pEmObj != NULL);
  306. delete pEmObj;
  307. }
  308. void CEmshellApp::GetStatusString(LONG lStatus, CString &csStatusStr)
  309. {
  310. int nId = -1;
  311. csStatusStr = _T("");
  312. switch(lStatus)
  313. {
  314. case STAT_SESS_NOT_STARTED_RUNNING:
  315. nId = IDS_STAT_SESS_NOT_STARTED_RUNNING;
  316. break;
  317. case STAT_SESS_NOT_STARTED_FILECREATED_SUCCESSFULLY:
  318. nId = IDS_STAT_SESS_NOT_STARTED_FILECREATED_SUCCESSFULLY;
  319. break;
  320. case STAT_SESS_NOT_STARTED_FILECREATION_FAILED:
  321. nId = IDS_STAT_SESS_NOT_STARTED_FILECREATION_FAILED;
  322. break;
  323. case STAT_SESS_NOT_STARTED_NOTRUNNING:
  324. nId = IDS_STAT_SESS_NOT_STARTED_NOTRUNNING;
  325. break;
  326. case STAT_SESS_DEBUG_IN_PROGRESS_NONE:
  327. nId = IDS_STAT_SESS_DEBUG_IN_PROGRESS_NONE;
  328. break;
  329. case STAT_SESS_DEBUG_IN_PROGRESS_FILECREATED_SUCESSFULLY:
  330. nId = IDS_STAT_SESS_DEBUG_IN_PROGRESS_FILECREATED_SUCESSFULLY;
  331. break;
  332. case STAT_SESS_DEBUG_IN_PROGRESS_FILECREATION_FAILED:
  333. nId = IDS_STAT_SESS_DEBUG_IN_PROGRESS_FILECREATION_FAILED;
  334. break;
  335. case STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_NONE:
  336. nId = IDS_STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_NONE;
  337. break;
  338. case STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_FILECREATED_SUCESSFULLY:
  339. nId = IDS_STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_FILECREATED_SUCESSFULLY;
  340. break;
  341. case STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_FILECREATION_FAILED:
  342. nId = IDS_STAT_SESS_DEBUG_IN_PROGRESS_ORPHAN_FILECREATION_FAILED;
  343. break;
  344. case STAT_SESS_STOPPED_SUCCESS:
  345. nId = IDS_STAT_SESS_STOPPED_SUCCESS;
  346. break;
  347. case STAT_SESS_STOPPED_FAILED:
  348. nId = IDS_STAT_SESS_STOPPED_FAILED;
  349. break;
  350. case STAT_SESS_STOPPED_ORPHAN_SUCCESS:
  351. nId = IDS_STAT_SESS_STOPPED_ORPHAN_SUCCESS;
  352. break;
  353. case STAT_SESS_STOPPED_ORPHAN_FAILED:
  354. nId = IDS_STAT_SESS_STOPPED_ORPHAN_FAILED;
  355. break;
  356. case STAT_SESS_STOPPED_DEBUGGEE_KILLED:
  357. nId = IDS_STAT_SESS_STOPPED_DEBUGGEE_KILLED;
  358. break;
  359. case STAT_SESS_STOPPED_DEBUGGEE_EXITED:
  360. nId = IDS_STAT_SESS_STOPPED_DEBUGGEE_EXITED;
  361. break;
  362. case STAT_SESS_STOPPED_EXCEPTION_OCCURED:
  363. nId = IDS_STAT_SESS_STOPPED_EXCEPTION_OCCURED;
  364. break;
  365. case STAT_SESS_STOPPED_ORPHAN_DEBUGGEE_KILLED:
  366. nId = IDS_STAT_SESS_STOPPED_ORPHAN_DEBUGGEE_KILLED;
  367. break;
  368. case STAT_SESS_STOPPED_ORPHAN_DEBUGGEE_EXITED:
  369. nId = IDS_STAT_SESS_STOPPED_ORPHAN_DEBUGGEE_EXITED;
  370. break;
  371. case STAT_SESS_STOPPED_ORPHAN_EXCEPTION_OCCURED:
  372. nId = IDS_STAT_SESS_STOPPED_ORPHAN_EXCEPTION_OCCURED;
  373. break;
  374. case STAT_SESS_STOPPED_ACCESSVIOLATION_OCCURED:
  375. nId = IDS_STAT_SESS_STOPPED_ACCESSVIOLATION_OCCURED;
  376. break;
  377. case STAT_SESS_STOPPED_ORPHAN_ACCESSVIOLATION_OCCURED:
  378. nId = IDS_STAT_SESS_STOPPED_ORPHAN_ACCESSVIOLATION_OCCURED;
  379. break;
  380. default:
  381. return;
  382. }
  383. csStatusStr.LoadString(nId);
  384. }
  385. void CEmshellApp::GetCDBPathFromRegistry()
  386. {
  387. CRegKey emshell;
  388. LONG lRes = NULL;
  389. DWORD dwSize = 0;
  390. LPTSTR pString = NULL;
  391. do {
  392. //Open the key
  393. lRes = emshell.Open( HKEY_LOCAL_MACHINE, EMSVC_SESSION_KEY );
  394. if( lRes != ERROR_SUCCESS ) break;
  395. //Get the size of the string in the registry
  396. lRes = emshell.QueryValue( pString, gtcEmDir, &dwSize);
  397. if ( lRes != ERROR_FILE_NOT_FOUND ) {
  398. pString = m_strApplicationPath.GetBuffer( dwSize + sizeof( TCHAR ));
  399. lRes = emshell.QueryValue( pString, gtcEmDir, &dwSize );
  400. m_strApplicationPath.ReleaseBuffer();
  401. if( lRes != ERROR_SUCCESS ) break;
  402. }
  403. } while( FALSE );
  404. if ( lRes != ERROR_SUCCESS ) {
  405. MessageBox(NULL, _T("Unable to get application install path from registry.\n Using help might not function properly."), _T("Registry operation failed"), MB_OK);
  406. }
  407. }
  408. DWORD CEmshellApp::ReadDataFromRegistry ( HKEY hKey, LPCTSTR lpKey )
  409. {
  410. CRegKey emshell;
  411. DWORD dwSize = 0;
  412. LPTSTR pString = NULL;
  413. LONG lRes = NULL;
  414. do {
  415. //Open the key
  416. lRes = emshell.Open( hKey, lpKey );
  417. if( lRes != ERROR_SUCCESS ) break;
  418. lRes = emshell.QueryValue( m_dwWindowHeight, gtcWindowHeight );
  419. if( lRes == ERROR_FILE_NOT_FOUND ) {
  420. m_dwWindowHeight = gnDefWindowHeight;
  421. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcWindowHeight, m_dwWindowHeight ) != ERROR_SUCCESS ) {
  422. break;
  423. }
  424. }
  425. lRes = emshell.QueryValue( m_dwWindowWidth, gtcWindowWidth );
  426. if( lRes == ERROR_FILE_NOT_FOUND ) {
  427. m_dwWindowWidth = gnDefWindowWidth;
  428. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcWindowWidth, m_dwWindowWidth ) != ERROR_SUCCESS ) {
  429. break;
  430. }
  431. }
  432. lRes = emshell.QueryValue( m_dwShowMSInfoDlg, gtcShowMSInfoDlg );
  433. if( lRes == ERROR_FILE_NOT_FOUND ) {
  434. m_dwShowMSInfoDlg = gnDefShowMSInfoDlgFlag;
  435. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcShowMSInfoDlg, m_dwShowMSInfoDlg ) != ERROR_SUCCESS ) {
  436. break;
  437. }
  438. }
  439. lRes = emshell.QueryValue( m_dwSessionRefreshRate, gtcPollSessionsFreq );
  440. if( lRes == ERROR_FILE_NOT_FOUND ) {
  441. m_dwSessionRefreshRate = gnDefSessionRefreshRate;
  442. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcPollSessionsFreq, m_dwSessionRefreshRate ) != ERROR_SUCCESS ) {
  443. break;
  444. }
  445. }
  446. lRes = emshell.QueryValue( m_dwRecursive, gtcRecursive );
  447. if( lRes == ERROR_FILE_NOT_FOUND ) {
  448. m_dwRecursive = gnDefRecursiveFlag;
  449. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcRecursive, m_dwRecursive ) != ERROR_SUCCESS ) {
  450. break;
  451. }
  452. }
  453. lRes = emshell.QueryValue( m_dwNotifyAdmin, gtcNotifyAdmin );
  454. if( lRes == ERROR_FILE_NOT_FOUND ) {
  455. m_dwNotifyAdmin = gnDefNotifyAdminFlag;
  456. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcNotifyAdmin, m_dwNotifyAdmin ) != ERROR_SUCCESS ) {
  457. break;
  458. }
  459. }
  460. lRes = emshell.QueryValue( m_dwCommandSet, gtcCommandSet );
  461. if( lRes == ERROR_FILE_NOT_FOUND ) {
  462. m_dwCommandSet = gnDefCommandSetFlag;
  463. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcCommandSet, m_dwCommandSet ) != ERROR_SUCCESS ) {
  464. break;
  465. }
  466. }
  467. lRes = emshell.QueryValue( m_dwMiniDump, gtcMiniDump );
  468. if( lRes == ERROR_FILE_NOT_FOUND ) {
  469. m_dwMiniDump = gnDefMiniDumpFlag;
  470. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcMiniDump, m_dwMiniDump ) != ERROR_SUCCESS ) {
  471. break;
  472. }
  473. }
  474. lRes = emshell.QueryValue( m_dwUserDump, gtcUserDump );
  475. if( lRes == ERROR_FILE_NOT_FOUND ) {
  476. m_dwUserDump = gnDefUserDumpFlag;
  477. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcUserDump, m_dwUserDump ) != ERROR_SUCCESS ) {
  478. break;
  479. }
  480. }
  481. lRes = emshell.QueryValue( m_dwMsinfoDump, gtcMsinfoDump );
  482. if( lRes == ERROR_FILE_NOT_FOUND ) {
  483. m_dwMsinfoDump = gnDefMSInfoDumpFlag;
  484. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcMsinfoDump, m_dwMsinfoDump ) != ERROR_SUCCESS ) {
  485. break;
  486. }
  487. }
  488. dwSize = 0;
  489. //Get the size of the string in the registry
  490. lRes = emshell.QueryValue( pString, gtcAdminName, &dwSize);
  491. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  492. //Create the entry
  493. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcAdminName, gtcDefAdminName ) != ERROR_SUCCESS ) {
  494. break;
  495. }
  496. } else {
  497. pString = m_strAdminName.GetBuffer( dwSize + sizeof( TCHAR ));
  498. lRes = emshell.QueryValue( pString, gtcAdminName, &dwSize );
  499. m_strAdminName.ReleaseBuffer();
  500. if( lRes != ERROR_SUCCESS ) break;
  501. }
  502. dwSize = 0;
  503. //Get the size of the string in the registry
  504. lRes = emshell.QueryValue( pString, gtcAltSymbolPath, &dwSize);
  505. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  506. //Create the entry
  507. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcAltSymbolPath, gtcDefAltSymbolPath ) != ERROR_SUCCESS ) {
  508. break;
  509. }
  510. } else {
  511. pString = m_strAltSymbolPath.GetBuffer( dwSize + sizeof( TCHAR ));
  512. lRes = emshell.QueryValue( pString, gtcAltSymbolPath, &dwSize );
  513. m_strAltSymbolPath.ReleaseBuffer();
  514. if( lRes != ERROR_SUCCESS ) break;
  515. }
  516. dwSize = 0;
  517. //Get the size of the string in the registry
  518. lRes = emshell.QueryValue( pString, gtcSelectedCommandSet, &dwSize);
  519. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  520. //Create the entry
  521. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcSelectedCommandSet, gtcDefSelectedCommandSet ) != ERROR_SUCCESS ) {
  522. break;
  523. }
  524. } else {
  525. pString = m_strCommandSet.GetBuffer( dwSize + sizeof( TCHAR ));
  526. lRes = emshell.QueryValue( pString, gtcSelectedCommandSet, &dwSize );
  527. m_strCommandSet.ReleaseBuffer();
  528. if( lRes != ERROR_SUCCESS ) break;
  529. }
  530. dwSize = 0;
  531. //Get the size of the string in the registry
  532. lRes = emshell.QueryValue( pString, gtcPassword, &dwSize);
  533. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  534. //Create the entry
  535. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcPassword, gtcDefPassword ) != ERROR_SUCCESS ) {
  536. break;
  537. }
  538. } else {
  539. pString = m_strPassword.GetBuffer( dwSize + sizeof( TCHAR ));
  540. lRes = emshell.QueryValue( pString, gtcPassword, &dwSize );
  541. m_strPassword.ReleaseBuffer();
  542. if( lRes != ERROR_SUCCESS ) break;
  543. }
  544. dwSize = 0;
  545. //Get the size of the string in the registry
  546. lRes = emshell.QueryValue( pString, gtcPort, &dwSize);
  547. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  548. //Create the entry
  549. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcPort, gtcDefPort ) != ERROR_SUCCESS ) {
  550. break;
  551. }
  552. } else {
  553. pString = m_strPort.GetBuffer( dwSize + sizeof( TCHAR ));
  554. lRes = emshell.QueryValue( pString, gtcPort, &dwSize );
  555. m_strPort.ReleaseBuffer();
  556. if( lRes != ERROR_SUCCESS ) break;
  557. }
  558. dwSize = 0;
  559. //Get the size of the string in the registry
  560. lRes = emshell.QueryValue( pString, gtcUsername, &dwSize);
  561. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  562. //Create the entry
  563. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcUsername, gtcDefUsername ) != ERROR_SUCCESS ) {
  564. break;
  565. }
  566. } else {
  567. pString = m_strUsername.GetBuffer( dwSize + sizeof( TCHAR ));
  568. lRes = emshell.QueryValue( pString, gtcUsername, &dwSize );
  569. m_strUsername.ReleaseBuffer();
  570. if( lRes != ERROR_SUCCESS ) break;
  571. }
  572. dwSize = 0;
  573. //Get the size of the string in the registry
  574. lRes = emshell.QueryValue( pString, gtcNoDebugProcesses, &dwSize);
  575. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  576. //Create the entry
  577. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcNoDebugProcesses, gtcNoDbgDefProcList ) != ERROR_SUCCESS ) {
  578. break;
  579. }
  580. } else {
  581. pString = m_strIgnoreProcesses.GetBuffer( dwSize + sizeof( TCHAR ));
  582. lRes = emshell.QueryValue( pString, gtcNoDebugProcesses, &dwSize );
  583. m_strIgnoreProcesses.ReleaseBuffer();
  584. if( lRes != ERROR_SUCCESS ) break;
  585. }
  586. dwSize = 0;
  587. //Get the size of the string in the registry
  588. lRes = emshell.QueryValue( pString, gtcWildCardNoDebugServices, &dwSize);
  589. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  590. //Create the entry
  591. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcWildCardNoDebugServices, gtcWldCrdDefList ) != ERROR_SUCCESS ) {
  592. break;
  593. }
  594. } else {
  595. pString = m_strWildCardIgnoreServices.GetBuffer( dwSize + sizeof( TCHAR ));
  596. lRes = emshell.QueryValue( pString, gtcWildCardNoDebugServices, &dwSize );
  597. m_strWildCardIgnoreServices.ReleaseBuffer();
  598. if( lRes != ERROR_SUCCESS ) break;
  599. }
  600. dwSize = 0;
  601. //Get the size of the string in the registry
  602. lRes = emshell.QueryValue( pString, gtcNoDebugServices, &dwSize);
  603. if ( lRes == ERROR_FILE_NOT_FOUND ) {
  604. //Create the entry
  605. if( lRes = CreateKeyAndSetData( hKey, lpKey, gtcNoDebugServices, gtcNoDbgDefSvcList ) != ERROR_SUCCESS ) {
  606. break;
  607. }
  608. } else {
  609. pString = m_strIgnoreServices.GetBuffer( dwSize + sizeof( TCHAR ) );
  610. lRes = emshell.QueryValue( pString, gtcNoDebugServices, &dwSize );
  611. m_strIgnoreServices.ReleaseBuffer();
  612. if( lRes != ERROR_SUCCESS ) break;
  613. }
  614. } while ( FALSE );
  615. if ( lRes != ERROR_SUCCESS ) {
  616. MessageBox(NULL, _T("Unable to set registry values."), _T("Registry operation failed"), MB_OK);
  617. }
  618. return lRes;
  619. }
  620. DWORD
  621. CEmshellApp::CreateEmShellRegEntries
  622. (
  623. HKEY hKey /* = HKEY_CURRENT_USER */,
  624. LPCTSTR lpszKey /* = _T("Software\\Microsoft\\EM\\shell") */
  625. )
  626. {
  627. LONG lRes = 0L;
  628. if( (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcPollSessionsFreq, m_dwSessionRefreshRate ) != ERROR_SUCCESS) ||
  629. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcWindowHeight, m_dwWindowHeight ) != ERROR_SUCCESS) ||
  630. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcWindowWidth, m_dwWindowWidth ) != ERROR_SUCCESS) ||
  631. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcRecursive, m_dwRecursive ) != ERROR_SUCCESS) ||
  632. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcCommandSet, m_dwCommandSet ) != ERROR_SUCCESS) ||
  633. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcMiniDump, m_dwMiniDump ) != ERROR_SUCCESS) ||
  634. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcUserDump, m_dwUserDump ) != ERROR_SUCCESS) ||
  635. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcNotifyAdmin, m_dwNotifyAdmin ) != ERROR_SUCCESS) ||
  636. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcMsinfoDump, m_dwMsinfoDump ) != ERROR_SUCCESS) ||
  637. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcAdminName, m_strAdminName ) != ERROR_SUCCESS) ||
  638. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcAltSymbolPath, m_strAltSymbolPath ) != ERROR_SUCCESS) ||
  639. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcSelectedCommandSet, m_strCommandSet ) != ERROR_SUCCESS) ||
  640. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcPassword, m_strPassword ) != ERROR_SUCCESS) ||
  641. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcPort, m_strPort ) != ERROR_SUCCESS) ||
  642. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcUsername, m_strUsername ) != ERROR_SUCCESS) ||
  643. (lRes = CreateKeyAndSetData( hKey, lpszKey, gtcShowMSInfoDlg, m_dwShowMSInfoDlg ) != ERROR_SUCCESS)
  644. ) {
  645. MessageBox(NULL, _T("Unable to set registry values."), _T("Registry operation failed"), MB_OK);
  646. }
  647. return lRes;
  648. }
  649. DWORD
  650. CEmshellApp::CreateKeyAndSetData
  651. (
  652. HKEY hKeyParent,
  653. LPCTSTR lpszKeyName,
  654. LPCTSTR lpszNamedValue,
  655. LPCTSTR lpValue,
  656. LPTSTR lpszClass /* = REG_NONE */
  657. )
  658. {
  659. CRegKey registry;
  660. do {
  661. if( registry.Create(hKeyParent, lpszKeyName, lpszClass) != ERROR_SUCCESS ) {
  662. return GetLastError();
  663. }
  664. if( registry.SetValue( lpValue, lpszNamedValue ) != ERROR_SUCCESS ) {
  665. return GetLastError();
  666. }
  667. }
  668. while( false );
  669. if( HKEY(registry) != NULL ) {
  670. registry.Close();
  671. }
  672. return 0L; // Successful
  673. }
  674. DWORD
  675. CEmshellApp::CreateKeyAndSetData
  676. (
  677. HKEY hKeyParent,
  678. LPCTSTR lpszKeyName,
  679. LPCTSTR lpszNamedValue,
  680. DWORD dwValue,
  681. LPTSTR lpszClass /* = REG_NONE */
  682. )
  683. {
  684. CRegKey registry;
  685. do {
  686. if( registry.Create(hKeyParent, lpszKeyName) != ERROR_SUCCESS ) {
  687. return GetLastError();
  688. }
  689. if( registry.SetValue( dwValue, lpszNamedValue ) != ERROR_SUCCESS ) {
  690. return GetLastError();
  691. }
  692. }
  693. while( false );
  694. if( HKEY(registry) != NULL ) {
  695. registry.Close();
  696. }
  697. return 0L; // Successful
  698. }
  699. void
  700. CEmshellApp::GetEmShellRegOptions
  701. (
  702. BOOL bReadFromRegistry /* = FALSE */,
  703. DWORD *pdwPollingSessionsFreq /* = NULL */,
  704. DWORD *pdwWindowHeight /* = NULL */,
  705. DWORD *pdwWindowWidth /* = NULL */,
  706. DWORD *pdwRecursive /* = NULL */,
  707. DWORD *pdwCommandSet /* = NULL */,
  708. DWORD *pdwMiniDump /* = NULL */,
  709. DWORD *pdwUserDump /* = NULL */,
  710. DWORD *pdwNotifyAdmin /* = NULL */,
  711. DWORD *pdwMsinfoDump /* = NULL */,
  712. CString *pstrAdminName /* = NULL */,
  713. CString *pstrAltSymbolPath /* = NULL */,
  714. CString *pstrCommandSet /* = NULL */,
  715. CString *pstrPassword /* = NULL */,
  716. CString *pstrPort /* = NULL */,
  717. CString *pstrUsername /* = NULL */,
  718. DWORD *pdwShowMSInfoDlg /* = NULL */
  719. )
  720. {
  721. if( bReadFromRegistry ) { ReadDataFromRegistry(); }
  722. if( pdwPollingSessionsFreq ) *pdwPollingSessionsFreq = m_dwSessionRefreshRate; // MilliSeconds
  723. if( pdwWindowHeight ) *pdwWindowHeight = m_dwWindowHeight;
  724. if( pdwWindowWidth ) *pdwWindowWidth = m_dwWindowWidth;
  725. if( pdwRecursive ) *pdwRecursive = m_dwRecursive;
  726. if( pdwCommandSet ) *pdwCommandSet = m_dwCommandSet;
  727. if( pdwMiniDump ) *pdwMiniDump = m_dwMiniDump;
  728. if( pdwUserDump ) *pdwUserDump = m_dwUserDump;
  729. if( pdwNotifyAdmin ) *pdwNotifyAdmin = m_dwNotifyAdmin;
  730. if( pdwMsinfoDump ) *pdwMsinfoDump = m_dwMsinfoDump;
  731. if( pstrAdminName ) *pstrAdminName = m_strAdminName;
  732. if( pstrAltSymbolPath ) *pstrAltSymbolPath = m_strAltSymbolPath;
  733. if( pstrCommandSet ) *pstrCommandSet = m_strCommandSet;
  734. if( pstrPassword ) *pstrPassword = m_strPassword;
  735. if( pstrPort ) *pstrPort = m_strPort;
  736. if( pstrUsername ) *pstrUsername = m_strUsername;
  737. if( pdwShowMSInfoDlg ) *pdwShowMSInfoDlg = m_dwShowMSInfoDlg;
  738. }
  739. void
  740. CEmshellApp::SetEmShellRegOptions
  741. (
  742. const BOOL bUpdateRegistry /* = FALSE */,
  743. const DWORD *pdwPollingSessionsFreq /* = NULL */,
  744. const DWORD *pdwWindowHeight /* = NULL */,
  745. const DWORD *pdwWindowWidth /* = NULL */,
  746. const DWORD *pdwRecursive /* = NULL */,
  747. const DWORD *pdwCommandSet /* = NULL */,
  748. const DWORD *pdwMiniDump /* = NULL */,
  749. const DWORD *pdwUserDump /* = NULL */,
  750. const DWORD *pdwNotifyAdmin /* = NULL */,
  751. const DWORD *pdwMsinfoDump /* = NULL */,
  752. CString *pstrAdminName /* = NULL */,
  753. CString *pstrAltSymbolPath /* = NULL */,
  754. CString *pstrCommandSet /* = NULL */,
  755. CString *pstrPassword /* = NULL */,
  756. CString *pstrPort /* = NULL */,
  757. CString *pstrUsername /* = NULL */,
  758. const DWORD *pdwShowMSInfoDlg /* = NULL */
  759. )
  760. {
  761. if( pdwPollingSessionsFreq ) m_dwSessionRefreshRate = *pdwPollingSessionsFreq; // will be stored as secs.
  762. if( pdwWindowHeight ) m_dwWindowHeight = *pdwWindowHeight;
  763. if( pdwWindowWidth ) m_dwWindowWidth = *pdwWindowWidth;
  764. if( pdwRecursive ) m_dwRecursive = *pdwRecursive;
  765. if( pdwCommandSet ) m_dwCommandSet = *pdwCommandSet;
  766. if( pdwMiniDump ) m_dwMiniDump = *pdwMiniDump;
  767. if( pdwUserDump ) m_dwUserDump = *pdwUserDump;
  768. if( pdwNotifyAdmin ) m_dwNotifyAdmin = *pdwNotifyAdmin;
  769. if( pdwMsinfoDump ) m_dwMsinfoDump = *pdwMsinfoDump;
  770. if( pstrAdminName ) m_strAdminName = *pstrAdminName;
  771. if( pstrAltSymbolPath ) m_strAltSymbolPath = *pstrAltSymbolPath;
  772. if( pstrCommandSet ) m_strCommandSet = *pstrCommandSet;
  773. if( pstrPassword ) m_strPassword = *pstrPassword;
  774. if( pstrPort ) m_strPort = *pstrPort;
  775. if( pstrUsername ) m_strUsername = *pstrUsername;
  776. if( pdwShowMSInfoDlg ) m_dwShowMSInfoDlg = *pdwShowMSInfoDlg;
  777. if( bUpdateRegistry ) { CreateEmShellRegEntries(); }
  778. }
  779. void __stdcall _com_issue_error( HRESULT hr )
  780. {
  781. throw _com_error ( hr );
  782. }
  783. BOOL CEmshellApp::AskForPath( CString &strDirPath )
  784. {
  785. LPITEMIDLIST lpItemIDlist = NULL;
  786. UINT nFlags = BIF_NEWDIALOGSTYLE;
  787. BOOL bRetVal = FALSE;
  788. TCHAR szDisplayName[_MAX_PATH];
  789. TCHAR szBuffer[_MAX_PATH];
  790. CString strTitle;
  791. BROWSEINFO browseInfo;
  792. LPMALLOC lpMalloc; // pointer to IMalloc
  793. strTitle.LoadString( IDS_EXPORT_FILES_CAPTION );
  794. //Initialize the browseinfo object
  795. browseInfo.hwndOwner = ::AfxGetMainWnd()->m_hWnd; // set root at Desktop
  796. browseInfo.pidlRoot = NULL;
  797. browseInfo.pszDisplayName = szDisplayName;
  798. browseInfo.lpszTitle = strTitle; // passed in
  799. browseInfo.ulFlags = nFlags; // also passed in
  800. browseInfo.lpfn = NULL; // not used
  801. browseInfo.lParam = 0; // not used
  802. do {
  803. if (::SHGetMalloc(&lpMalloc) != NOERROR) break; // failed to get allocator
  804. if ((lpItemIDlist = ::SHBrowseForFolder(&browseInfo)) != NULL)
  805. {
  806. // Get the path of the selected folder from the item ID list.
  807. if (::SHGetPathFromIDList(lpItemIDlist, szBuffer)) {
  808. // At this point, szBuffer contains the path the user chose.
  809. if (szBuffer[0] == '\0') {
  810. strTitle.LoadString( IDS_EXPORT_FAILED_GET_DIRECTORY );
  811. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString( strTitle );
  812. break;
  813. }
  814. // We have a path in szBuffer!
  815. // Return it.
  816. strDirPath = szBuffer;
  817. bRetVal = TRUE;
  818. }
  819. }
  820. else {
  821. break;
  822. }
  823. if ( strDirPath[strDirPath.GetLength() - 1 ] != CString( _T("\\") ) )
  824. strDirPath += _T("\\");
  825. } while ( FALSE );
  826. if ( lpItemIDlist ) {
  827. lpMalloc->Free( lpItemIDlist );
  828. lpItemIDlist = NULL;
  829. }
  830. if ( lpMalloc ) {
  831. lpMalloc->Release();
  832. lpMalloc = NULL;
  833. }
  834. return bRetVal;
  835. }
  836. HRESULT CEmshellApp::ExportLog( PEmObject pEmObject, CString strDirPath, IEmManager* pEmManager )
  837. {
  838. char lpszLogData[ISTREAM_BUFFER_SIZE];
  839. BSTR bstrEmObject = NULL;
  840. HRESULT hr = E_FAIL;
  841. IStream* pIEmStream = NULL;
  842. ULONG lRead = 0L;
  843. size_t tWritten = 0;
  844. FILE* pLogFile = NULL;
  845. CString strMessage;
  846. do {
  847. //Initialize the bstrEmObject for the call to the server
  848. bstrEmObject = CopyBSTR ( (LPBYTE)pEmObject, sizeof( EmObject ) );
  849. if( bstrEmObject == NULL ){
  850. hr = E_OUTOFMEMORY;
  851. break;
  852. }
  853. //Get an IStream* file pointer for the currently selected item.
  854. hr = pEmManager->GetEmFileInterface( bstrEmObject, (IStream **)&pIEmStream );
  855. if( FAILED( hr ) ) break;
  856. //Append the filename to the directory name
  857. strDirPath += pEmObject->szName;
  858. CFileFind finder;
  859. BOOL bFound = finder.FindFile( strDirPath );
  860. if ( bFound ) {
  861. strMessage.LoadString( IDS_FILEOVERWRITE_CONFIRMATION );
  862. //Ask the user if they want to overwrite, if not break.
  863. if (((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromString(strMessage, MB_YESNO) == IDNO) break;
  864. }
  865. //Set the cursor to a wait cursor
  866. CWaitCursor wait;
  867. //Create the file in the selected directory
  868. pLogFile = _tfopen( strDirPath, gtcFileOpenFlags );
  869. if ( pLogFile == NULL ) {
  870. hr = HRESULT_FROM_WIN32( GetLastError() );
  871. break;
  872. }
  873. //Read the stream into the file
  874. do {
  875. hr = pIEmStream->Read( (void *)lpszLogData, ISTREAM_BUFFER_SIZE, &lRead );
  876. if ( lRead == 0 || FAILED( hr ) ) break;
  877. tWritten = fwrite( lpszLogData, sizeof( char ), lRead, pLogFile );
  878. if ( tWritten == 0 ) {
  879. hr = E_FAIL;
  880. break;
  881. }
  882. } while (TRUE);
  883. if ( FAILED( hr ) ) break;
  884. } while ( FALSE );
  885. if ( FAILED( hr ) ) {
  886. ((CEmshellApp*)AfxGetApp())->DisplayErrMsgFromHR( hr );
  887. }
  888. if ( pIEmStream ) {
  889. SAFE_RELEASEIX( pIEmStream );
  890. }
  891. if ( pLogFile ) {
  892. fclose( pLogFile );
  893. pLogFile = NULL;
  894. }
  895. return( hr );
  896. }
  897. BOOL CEmshellApp::CanDisplayProcess(TCHAR *pszName)
  898. {
  899. BOOL bRetVal = TRUE;
  900. TCHAR* pszIgnoreProcesses = new TCHAR[m_strIgnoreProcesses.GetLength() + sizeof(TCHAR)];
  901. TCHAR* token = NULL;
  902. wcscpy( pszIgnoreProcesses, m_strIgnoreProcesses );
  903. //Tokenize and iterate through each element in the string comparing the
  904. //element with the service name
  905. token = wcstok( pszIgnoreProcesses, _T(";") );
  906. while( token != NULL )
  907. {
  908. if ( !_wcsicmp( token, pszName ) ) {
  909. bRetVal = FALSE;
  910. break;
  911. }
  912. /* Get next token: */
  913. token = wcstok( NULL, _T(";") );
  914. }
  915. delete[] pszIgnoreProcesses;
  916. return bRetVal;
  917. }
  918. BOOL CEmshellApp::CanDisplayService(TCHAR *pszName, TCHAR *pszSecName)
  919. {
  920. BOOL bRetVal = TRUE;
  921. TCHAR* pszIgnoreServices = new TCHAR[m_strIgnoreServices.GetLength() + sizeof(TCHAR)];
  922. ASSERT( pszIgnoreServices != NULL );
  923. if( pszIgnoreServices == NULL ) return bRetVal;
  924. TCHAR* pszWildCardIgnoreServices = new TCHAR[m_strWildCardIgnoreServices.GetLength() + sizeof(TCHAR)];
  925. ASSERT( pszWildCardIgnoreServices != NULL );
  926. if( pszWildCardIgnoreServices == NULL ) {
  927. delete pszWildCardIgnoreServices;
  928. return bRetVal;
  929. }
  930. TCHAR* token = NULL;
  931. do {
  932. wcscpy( pszWildCardIgnoreServices, m_strWildCardIgnoreServices );
  933. //Tokenize and iterate through each element in the string looking for each
  934. //element within the service name
  935. token = wcstok( pszWildCardIgnoreServices, _T(";") );
  936. while( token != NULL )
  937. {
  938. if ( wcsstr( _wcslwr( pszName ), _wcslwr( token ) ) ) {
  939. bRetVal = FALSE;
  940. break;
  941. }
  942. /* Get next token: */
  943. token = wcstok( NULL, _T(";") );
  944. }
  945. //Break out if we know we can't show it.
  946. if ( !bRetVal ) break;
  947. wcscpy( pszIgnoreServices, m_strIgnoreServices );
  948. //Tokenize and iterate through each element in the string comparing the
  949. //element with the service name
  950. token = wcstok( pszIgnoreServices, _T(";") );
  951. while( token != NULL )
  952. {
  953. if ( !_wcsicmp( token, pszSecName ) ) {
  954. bRetVal = FALSE;
  955. break;
  956. }
  957. /* Get next token: */
  958. token = wcstok( NULL, _T(";") );
  959. }
  960. } while ( FALSE );
  961. delete[] pszIgnoreServices;
  962. delete[] pszWildCardIgnoreServices;
  963. return bRetVal;
  964. }
  965. void CEmshellApp::UpdateSessionData( BOOL bUpdate )
  966. {
  967. if( bUpdate ) {
  968. //Write out the session info to the app registry entries
  969. m_dwCommandSet = m_SessionSettings.dwCommandSet;
  970. m_dwMiniDump = m_SessionSettings.dwProduceMiniDump;
  971. m_dwRecursive = m_SessionSettings.dwRecursiveMode;
  972. m_dwUserDump = m_SessionSettings.dwProduceUserDump;
  973. m_dwNotifyAdmin = m_SessionSettings.dwNotifyAdmin;
  974. m_strAdminName = m_SessionSettings.strAdminName;
  975. m_strAltSymbolPath = m_SessionSettings.strAltSymbolPath;
  976. m_strCommandSet = m_SessionSettings.strCommandSet;
  977. m_strPassword = m_SessionSettings.strPassword;
  978. m_strUsername = m_SessionSettings.strUsername;
  979. m_strPort = m_SessionSettings.strPort;
  980. //Flush the changes to the registry
  981. CreateEmShellRegEntries();
  982. }
  983. else {
  984. //Retrieve the session info from the app registry entries
  985. m_SessionSettings.dwCommandSet = m_dwCommandSet;
  986. m_SessionSettings.dwProduceMiniDump = m_dwMiniDump;
  987. m_SessionSettings.dwRecursiveMode = m_dwRecursive;
  988. m_SessionSettings.dwProduceUserDump = m_dwUserDump;
  989. m_SessionSettings.dwNotifyAdmin = m_dwNotifyAdmin;
  990. m_SessionSettings.strAdminName = m_strAdminName;
  991. m_SessionSettings.strAltSymbolPath = m_strAltSymbolPath;
  992. m_SessionSettings.strCommandSet = m_strCommandSet;
  993. m_SessionSettings.strPassword = m_strPassword;
  994. m_SessionSettings.strUsername = m_strUsername;
  995. m_SessionSettings.strPort = m_strPort;
  996. }
  997. }