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.

320 lines
8.1 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. // WMITest.cpp : Defines the class behaviors for the application.
  8. //
  9. #include "stdafx.h"
  10. #include "WMITest.h"
  11. #include "MainFrm.h"
  12. #include "WMITestDoc.h"
  13. #include "OpView.h"
  14. #include <cominit.h> // for SetInterfaceSecurityEx()
  15. #include "Utils.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CWMITestApp
  23. BEGIN_MESSAGE_MAP(CWMITestApp, CWinApp)
  24. //{{AFX_MSG_MAP(CWMITestApp)
  25. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  26. // NOTE - the ClassWizard will add and remove mapping macros here.
  27. // DO NOT EDIT what you see in these blocks of generated code!
  28. //}}AFX_MSG_MAP
  29. // Standard file based document commands
  30. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  31. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CWMITestApp construction
  35. CWMITestApp::CWMITestApp()
  36. {
  37. // TODO: add construction code here,
  38. // Place all significant initialization in InitInstance
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CWMITestApp object
  42. CWMITestApp theApp;
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CWMITestApp initialization
  45. BOOL CWMITestApp::InitInstance()
  46. {
  47. // Standard initialization
  48. // If you are not using these features and wish to reduce the size
  49. // of your final executable, you should remove from the following
  50. // the specific initialization routines you do not need.
  51. #ifdef _AFXDLL
  52. Enable3dControls(); // Call this when using MFC in a shared DLL
  53. #else
  54. Enable3dControlsStatic(); // Call this when linking to MFC statically
  55. #endif
  56. // Change the registry key under which our settings are stored.
  57. // TODO: You should modify this string to be something appropriate
  58. // such as the name of your company or organization.
  59. SetRegistryKey(_T("Microsoft"));
  60. LoadStdProfileSettings(16); // Load standard INI file options (including MRU)
  61. //AfxOleInit();
  62. if (FAILED(InitializeCom()))
  63. {
  64. AfxMessageBox(IDS_COM_INIT_FAILED);
  65. return FALSE;
  66. }
  67. /*
  68. CFileDialog file(TRUE);
  69. file.m_ofn.Flags |= OFN_NODEREFERENCELINKS;
  70. file.DoModal();
  71. */
  72. InitializeSecurity(
  73. NULL, -1, NULL, NULL,
  74. RPC_C_AUTHN_LEVEL_NONE,
  75. RPC_C_IMP_LEVEL_IMPERSONATE,
  76. NULL, EOAC_NONE, 0);
  77. m_bLoadLastFile = GetProfileInt(_T("Settings"), _T("LoadLast"), TRUE);
  78. m_bShowSystemProperties = GetProfileInt(_T("Settings"), _T("ShowSys"), TRUE);
  79. m_bShowInheritedProperties = GetProfileInt(_T("Settings"), _T("ShowInherited"), TRUE);
  80. m_bTranslateValues = GetProfileInt(_T("Settings"), _T("TranslateValues"), TRUE);
  81. m_dwUpdateFlag = GetProfileInt(_T("Settings"), _T("UpdateFlag"),
  82. WBEM_FLAG_CREATE_OR_UPDATE);
  83. m_dwClassUpdateMode = GetProfileInt(_T("Settings"), _T("ClassUpdateMode"),
  84. WBEM_FLAG_UPDATE_COMPATIBLE);
  85. m_bDelFromWMI = GetProfileInt(_T("Settings"), _T("DelFromWMI"), TRUE);
  86. m_bEnablePrivsOnStartup = GetProfileInt(_T("Settings"), _T("EnablePrivsOnStartup"), FALSE);
  87. if (m_bEnablePrivsOnStartup)
  88. {
  89. HRESULT hr = EnableAllPrivileges(TOKEN_PROCESS);
  90. if (SUCCEEDED(hr))
  91. m_bPrivsEnabled = TRUE;
  92. else
  93. AfxMessageBox(IDS_ENABLE_PRIVS_FAILED, hr);
  94. //CWMITestDoc::DisplayWMIErrorBox(hr);
  95. }
  96. /*
  97. HRESULT hr;
  98. // NOTE: This is needed to work around a security problem
  99. // when using IWBEMObjectSink. The sink wont normally accept
  100. // calls when the caller wont identify themselves. This
  101. // waives that process.
  102. hr =
  103. CoInitializeSecurity(
  104. NULL,
  105. -1,
  106. NULL,
  107. NULL,
  108. RPC_C_AUTHN_LEVEL_CONNECT,
  109. RPC_C_IMP_LEVEL_IDENTIFY,
  110. NULL,
  111. 0,
  112. 0);
  113. */
  114. // Register the application's document templates. Document templates
  115. // serve as the connection between documents, frame windows and views.
  116. CSingleDocTemplate* pDocTemplate;
  117. pDocTemplate = new CSingleDocTemplate(
  118. IDR_MAINFRAME,
  119. RUNTIME_CLASS(CWMITestDoc),
  120. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  121. RUNTIME_CLASS(COpView));
  122. AddDocTemplate(pDocTemplate);
  123. // Enable DDE Execute open
  124. EnableShellOpen();
  125. RegisterShellFileTypes(TRUE);
  126. // Parse command line for standard shell commands, DDE, file open
  127. /*
  128. CCommandLineInfo cmdInfo;
  129. ParseCommandLine(cmdInfo);
  130. // Dispatch commands specified on the command line
  131. if (!ProcessShellCommand(cmdInfo))
  132. return FALSE;
  133. */
  134. CCommandLineInfo cmdInfo;
  135. ParseCommandLine(cmdInfo);
  136. BOOL bModifiedParams = FALSE;
  137. #if 1
  138. if (!(*m_pRecentFileList)[0].IsEmpty() &&
  139. cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew &&
  140. m_bLoadLastFile)
  141. {
  142. cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
  143. cmdInfo.m_strFileName = (*m_pRecentFileList)[0];
  144. bModifiedParams = TRUE;
  145. }
  146. #endif
  147. // Dispatch commands specified on the command line
  148. if (!ProcessShellCommand(cmdInfo))
  149. {
  150. if (bModifiedParams)
  151. {
  152. // If we failed to open the last .qvw file, change
  153. // the option to new and continue.
  154. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNew;
  155. cmdInfo.m_strFileName = "";
  156. if (!ProcessShellCommand(cmdInfo))
  157. return FALSE;
  158. }
  159. else
  160. return FALSE;
  161. }
  162. // The one and only window has been initialized, so show and update it.
  163. m_pMainWnd->ShowWindow(SW_SHOW);
  164. m_pMainWnd->UpdateWindow();
  165. // Enable drag/drop open
  166. m_pMainWnd->DragAcceptFiles();
  167. ((CWMITestDoc*) ((CMainFrame*) m_pMainWnd)->GetActiveDocument())->AutoConnect();
  168. //CoInitialize(NULL);
  169. return TRUE;
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CAboutDlg dialog used for App About
  173. class CAboutDlg : public CDialog
  174. {
  175. public:
  176. CAboutDlg();
  177. // Dialog Data
  178. //{{AFX_DATA(CAboutDlg)
  179. enum { IDD = IDD_ABOUTBOX };
  180. //}}AFX_DATA
  181. // ClassWizard generated virtual function overrides
  182. //{{AFX_VIRTUAL(CAboutDlg)
  183. protected:
  184. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  185. //}}AFX_VIRTUAL
  186. // Implementation
  187. protected:
  188. //{{AFX_MSG(CAboutDlg)
  189. virtual BOOL OnInitDialog();
  190. //}}AFX_MSG
  191. DECLARE_MESSAGE_MAP()
  192. };
  193. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  194. {
  195. //{{AFX_DATA_INIT(CAboutDlg)
  196. //}}AFX_DATA_INIT
  197. }
  198. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  199. {
  200. CDialog::DoDataExchange(pDX);
  201. //{{AFX_DATA_MAP(CAboutDlg)
  202. //}}AFX_DATA_MAP
  203. }
  204. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  205. //{{AFX_MSG_MAP(CAboutDlg)
  206. //}}AFX_MSG_MAP
  207. END_MESSAGE_MAP()
  208. // App command to run the dialog
  209. void CWMITestApp::OnAppAbout()
  210. {
  211. CAboutDlg aboutDlg;
  212. aboutDlg.DoModal();
  213. }
  214. /////////////////////////////////////////////////////////////////////////////
  215. // CWMITestApp message handlers
  216. int CWMITestApp::ExitInstance()
  217. {
  218. CoUninitialize();
  219. //CoUninitialize();
  220. WriteProfileInt(_T("Settings"), _T("LoadLast"), m_bLoadLastFile);
  221. WriteProfileInt(_T("Settings"), _T("ShowSys"), m_bShowSystemProperties);
  222. WriteProfileInt(_T("Settings"), _T("ShowInherited"), m_bShowInheritedProperties);
  223. WriteProfileInt(_T("Settings"), _T("TranslateValues"), m_bTranslateValues);
  224. WriteProfileInt(_T("Settings"), _T("UpdateFlag"), m_dwUpdateFlag);
  225. WriteProfileInt(_T("Settings"), _T("ClassUpdateMode"), m_dwClassUpdateMode);
  226. WriteProfileInt(_T("Settings"), _T("DelFromWMI"), m_bDelFromWMI);
  227. WriteProfileInt(_T("Settings"), _T("EnablePrivsOnStartup"), m_bEnablePrivsOnStartup);
  228. return CWinApp::ExitInstance();
  229. }
  230. BOOL CAboutDlg::OnInitDialog()
  231. {
  232. CDialog::OnInitDialog();
  233. // Version info
  234. char szFilename[MAX_PATH],
  235. szVersion[100];
  236. GetModuleFileName(NULL, szFilename, sizeof(szFilename));
  237. if (GetFileVersion(szFilename, szVersion))
  238. {
  239. static CFont fontVersion;
  240. fontVersion.CreatePointFont(70, "Arial");
  241. GetDlgItem(IDS_VERSION)->SetFont(&fontVersion);
  242. SetDlgItemText(IDS_VERSION, szVersion);
  243. }
  244. return TRUE; // return TRUE unless you set the focus to a control
  245. // EXCEPTION: OCX Property Pages should return FALSE
  246. }