Leaked source code of windows server 2003
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.

778 lines
25 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. INTPROV.CPP
  5. Abstract:
  6. Defines the CIntProv class. An object of this class is
  7. created by the class factory for each connection.
  8. History:
  9. --*/
  10. #include "precomp.h"
  11. #include <stdio.h>
  12. #include <time.h>
  13. #include <locale.h>
  14. #include <wbemcore.h>
  15. #include <intprov.h>
  16. #include <objpath.h>
  17. #include <reg.h>
  18. #include <genutils.h>
  19. #include <safearry.h>
  20. //***************************************************************************
  21. //
  22. // Return: NULL if failure, otherwise the caller must call SysFreeString.
  23. //
  24. //***************************************************************************
  25. BSTR GetBSTR(WCHAR* pInput)
  26. {
  27. return SysAllocString(pInput);
  28. }
  29. //***************************************************************************
  30. //
  31. // HRESULT GetDateTime(FILETIME * pft, bool bLocalTime, LPWSTR Buff)
  32. //
  33. // Converts a FILETIME date to CIM_DATA representation.
  34. //
  35. // Parameters:
  36. // pft FILETIME to be converted.
  37. // bLocalTime If true, then the conversion is to local,
  38. // ex 19990219112222:000000+480. Otherwise it returns gmt
  39. // Buff WCHAR buffer to be passed by the caller. Should be 30 long
  40. //
  41. //***************************************************************************
  42. HRESULT GetDateTime(FILETIME * pft, bool bLocalTime, LPWSTR Buff, size_t cchBuffer)
  43. {
  44. if(pft == NULL || Buff == NULL)
  45. return WBEM_E_INVALID_PARAMETER;
  46. SYSTEMTIME st;
  47. int Bias=0;
  48. char cOffsetSign = '+';
  49. if(bLocalTime)
  50. {
  51. FILETIME lft; // local file time
  52. TIME_ZONE_INFORMATION ZoneInformation;
  53. // note that win32 and the DMTF interpret bias differently.
  54. // For example, win32 would give redmond a bias of 480 while
  55. // dmtf would have -480
  56. DWORD dwRet = GetTimeZoneInformation(&ZoneInformation);
  57. if(dwRet != TIME_ZONE_ID_UNKNOWN)
  58. Bias = -ZoneInformation.Bias;
  59. if(Bias < 0)
  60. {
  61. cOffsetSign = '-';
  62. Bias = -Bias;
  63. }
  64. FileTimeToLocalFileTime(
  65. pft, // pointer to UTC file time to convert
  66. &lft); // pointer to converted file time);
  67. if(!FileTimeToSystemTime(&lft, &st))
  68. return WBEM_E_FAILED;
  69. }
  70. if(!FileTimeToSystemTime(pft, &st))
  71. return WBEM_E_FAILED;
  72. StringCchPrintfW(Buff, cchBuffer, L"%4d%02d%02d%02d%02d%02d.%06d%c%03d",
  73. st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute,
  74. st.wSecond, st.wMilliseconds*1000, cOffsetSign, Bias);
  75. return S_OK;
  76. }
  77. //***************************************************************************
  78. //
  79. // CIntProv::CIntProv
  80. // CIntProv::~CIntProv
  81. //
  82. //***************************************************************************
  83. CIntProv::CIntProv()
  84. {
  85. m_pNamespace = NULL;
  86. m_cRef=0;
  87. gClientCounter.AddClientPtr(&m_Entry);
  88. }
  89. CIntProv::~CIntProv(void)
  90. {
  91. if(m_pNamespace)
  92. m_pNamespace->Release();
  93. gClientCounter.RemoveClientPtr(&m_Entry);
  94. }
  95. //***************************************************************************
  96. //
  97. // CIntProv::QueryInterface
  98. // CIntProv::AddRef
  99. // CIntProv::Release
  100. //
  101. // Purpose: IUnknown members for CIntProv object.
  102. //***************************************************************************
  103. STDMETHODIMP CIntProv::QueryInterface(REFIID riid, PPVOID ppv)
  104. {
  105. *ppv=NULL;
  106. // Since we have dual inheritance, it is necessary to cast the return type
  107. if(riid== IID_IWbemServices)
  108. *ppv=(IWbemServices*)this;
  109. if(IID_IUnknown==riid || riid== IID_IWbemProviderInit)
  110. *ppv=(IWbemProviderInit*)this;
  111. if (NULL!=*ppv) {
  112. AddRef();
  113. return NOERROR;
  114. }
  115. else
  116. return E_NOINTERFACE;
  117. }
  118. STDMETHODIMP_(ULONG) CIntProv::AddRef(void)
  119. {
  120. return InterlockedIncrement((long *)&m_cRef);
  121. }
  122. STDMETHODIMP_(ULONG) CIntProv::Release(void)
  123. {
  124. ULONG nNewCount = InterlockedDecrement((long *)&m_cRef);
  125. if (0L == nNewCount)
  126. delete this;
  127. return nNewCount;
  128. }
  129. /***********************************************************************
  130. * *
  131. * CIntProv::Initialize *
  132. * *
  133. * Purpose: This is the implementation of IWbemProviderInit. The method *
  134. * is need to initialize with CIMOM. *
  135. * *
  136. ***********************************************************************/
  137. STDMETHODIMP CIntProv::Initialize(LPWSTR pszUser, LONG lFlags,
  138. LPWSTR pszNamespace, LPWSTR pszLocale,
  139. IWbemServices *pNamespace,
  140. IWbemContext *pCtx,
  141. IWbemProviderInitSink *pInitSink)
  142. {
  143. if(pNamespace)
  144. pNamespace->AddRef();
  145. m_pNamespace = pNamespace;
  146. //Let CIMOM know you are initialized
  147. //==================================
  148. pInitSink->SetStatus(WBEM_S_INITIALIZED,0);
  149. return WBEM_S_NO_ERROR;
  150. }
  151. //***************************************************************************
  152. //
  153. // CIntProv::CreateInstanceEnumAsync
  154. //
  155. // Purpose: Asynchronously enumerates the instances.
  156. //
  157. //***************************************************************************
  158. SCODE CIntProv::CreateInstanceEnumAsync( const BSTR RefStr, long lFlags, IWbemContext *pCtx,
  159. IWbemObjectSink FAR* pHandler)
  160. {
  161. SCODE sc = WBEM_E_FAILED;
  162. IWbemClassObject FAR* pObj = NULL;
  163. if(RefStr == NULL || pHandler == NULL)
  164. return WBEM_E_INVALID_PARAMETER;
  165. ParsedObjectPath * pOutput = 0;
  166. CObjectPathParser p;
  167. int nStatus = p.Parse(RefStr, &pOutput);
  168. if(nStatus != 0)
  169. return WBEM_E_INVALID_PARAMETER;
  170. if(IsNT() && IsDcomEnabled())
  171. {
  172. sc = WbemCoImpersonateClient ( ) ; // SEC:REVIEWED 2002-03-22 : OK
  173. if ( FAILED ( sc ) )
  174. {
  175. return sc ;
  176. }
  177. }
  178. // if the path and class are for the setting object, go get it.
  179. if(pOutput->IsClass() && !wbem_wcsicmp(pOutput->m_pClass, L"Win32_WMISetting"))
  180. {
  181. sc = CreateWMISetting(&pObj, pCtx);
  182. }
  183. else if(pOutput->IsClass() && !wbem_wcsicmp(pOutput->m_pClass, L"Win32_WMIElementSetting"))
  184. {
  185. sc = CreateWMIElementSetting(&pObj, pCtx);
  186. }
  187. else
  188. sc = WBEM_E_INVALID_PARAMETER;
  189. p.Free(pOutput);
  190. if(pObj)
  191. {
  192. pHandler->Indicate(1,&pObj);
  193. pObj->Release();
  194. }
  195. // Set status
  196. pHandler->SetStatus(0,sc,NULL, NULL);
  197. return S_OK;
  198. }
  199. //***************************************************************************
  200. //
  201. // CIntProv::GetObjectAsync
  202. //
  203. // Purpose: Creates an instance given a particular path value.
  204. //
  205. //***************************************************************************
  206. SCODE CIntProv::GetObjectAsync(const BSTR ObjectPath, long lFlags,IWbemContext *pCtx,
  207. IWbemObjectSink FAR* pHandler)
  208. {
  209. SCODE sc = WBEM_E_FAILED;
  210. IWbemClassObject FAR* pObj = NULL;
  211. BOOL bOK = FALSE;
  212. // Do a check of arguments and make sure we have pointer to Namespace
  213. if(ObjectPath == NULL || pHandler == NULL || m_pNamespace == NULL)
  214. return WBEM_E_INVALID_PARAMETER;
  215. // do the get, pass the object on to the notify
  216. ParsedObjectPath * pOutput = 0;
  217. CObjectPathParser p;
  218. int nStatus = p.Parse(ObjectPath, &pOutput);
  219. if(nStatus != 0)
  220. return WBEM_E_INVALID_PARAMETER;
  221. if(IsNT() && IsDcomEnabled())
  222. {
  223. sc = WbemCoImpersonateClient ( ) ; // SEC:REVIEWED 2002-03-22 : OK
  224. if ( FAILED ( sc ) )
  225. {
  226. return sc ;
  227. }
  228. }
  229. // if the path and class are for the setting object, go get it.
  230. if(pOutput->m_bSingletonObj && !wbem_wcsicmp(pOutput->m_pClass, L"Win32_WMISetting"))
  231. {
  232. sc = CreateWMISetting(&pObj, pCtx);
  233. }
  234. if(!pOutput->m_bSingletonObj && !wbem_wcsicmp(pOutput->m_pClass, L"Win32_WMIElementSetting")
  235. && pOutput->m_dwNumKeys == 2)
  236. {
  237. WCHAR * pKey = pOutput->GetKeyString();
  238. if(pKey)
  239. {
  240. WCHAR * pTest = L"Win32_Service=\"winmgmt\"\xffffWin32_WMISetting=@";
  241. if(!wbem_wcsicmp(pKey, pTest))
  242. sc = CreateWMIElementSetting(&pObj, pCtx);
  243. delete [] pKey;
  244. }
  245. }
  246. if(pObj)
  247. {
  248. pHandler->Indicate(1,&pObj);
  249. pObj->Release();
  250. bOK = TRUE;
  251. }
  252. sc = (bOK) ? S_OK : WBEM_E_NOT_FOUND;
  253. // Set Status
  254. pHandler->SetStatus(0,sc, NULL, NULL);
  255. p.Free(pOutput);
  256. return sc;
  257. }
  258. //***************************************************************************
  259. //
  260. // CIntProv::PutInstanceAsync
  261. //
  262. // Purpose: Creates an instance given a particular path value.
  263. //
  264. //***************************************************************************
  265. SCODE CIntProv::PutInstanceAsync(IWbemClassObject __RPC_FAR *pInst, long lFlags,IWbemContext *pCtx,
  266. IWbemObjectSink FAR* pHandler)
  267. {
  268. SCODE sc = WBEM_E_FAILED;
  269. // Do a check of arguments and make sure we have pointer to Namespace
  270. if(pInst == NULL || pHandler == NULL || m_pNamespace == NULL)
  271. return WBEM_E_INVALID_PARAMETER;
  272. // Get the rel path and parse it;
  273. VARIANT var;
  274. VariantInit(&var);
  275. sc = pInst->Get(L"__relPath", 0, &var, NULL, NULL);
  276. if(sc != S_OK)
  277. return WBEM_E_INVALID_PARAMETER;
  278. // do the get, pass the object on to the notify
  279. ParsedObjectPath * pOutput = 0;
  280. CObjectPathParser p;
  281. int nStatus = p.Parse(var.bstrVal, &pOutput);
  282. VariantClear(&var);
  283. if(nStatus != 0)
  284. return WBEM_E_FAILED;
  285. if(IsNT() && IsDcomEnabled())
  286. {
  287. sc = WbemCoImpersonateClient ( ) ; // SEC:REVIEWED 2002-03-22 : OK
  288. if ( FAILED ( sc ) )
  289. {
  290. return sc ;
  291. }
  292. }
  293. // if the path and class are for the setting object, go get it.
  294. if(pOutput->m_bSingletonObj && !wbem_wcsicmp(pOutput->m_pClass, L"Win32_WMISetting"))
  295. {
  296. sc = SaveWMISetting(pInst);
  297. }
  298. p.Free(pOutput);
  299. // Set Status
  300. pHandler->SetStatus(0,sc, NULL, NULL);
  301. return S_OK;
  302. }
  303. //***************************************************************************
  304. //
  305. // CIntProv::CreateInstance
  306. //
  307. // Purpose: Creates an instance given a particular Path value.
  308. //
  309. //***************************************************************************
  310. SCODE CIntProv::CreateInstance(LPWSTR pwcClassName, IWbemClassObject FAR* FAR* ppObj,
  311. IWbemContext *pCtx)
  312. {
  313. SCODE sc;
  314. IWbemClassObject * pClass = NULL;
  315. sc = m_pNamespace->GetObject(pwcClassName, 0, pCtx, &pClass, NULL);
  316. if(sc != S_OK)
  317. return WBEM_E_FAILED;
  318. sc = pClass->SpawnInstance(0, ppObj);
  319. pClass->Release();
  320. return sc;
  321. }
  322. //***************************************************************************
  323. //
  324. // CIntProv::GetRegStrProp
  325. //
  326. // Retrieves a string property from the registry and puts it into the object.
  327. //
  328. //***************************************************************************
  329. SCODE CIntProv::GetRegStrProp(Registry & reg, LPTSTR pRegValueName, LPWSTR pwsPropName,
  330. CWbemObject * pObj)
  331. {
  332. SCODE sc;
  333. TCHAR *pszData = NULL;
  334. if (reg.GetStr(pRegValueName, &pszData))
  335. return WBEM_E_FAILED;
  336. CDeleteMe<TCHAR> del1(pszData);
  337. BSTR bstr = GetBSTR(pszData);
  338. if(bstr == NULL)
  339. return WBEM_E_OUT_OF_MEMORY;
  340. CVar var;
  341. var.SetBSTR(auto_bstr(bstr)); // this acquires and frees the bstr
  342. sc = pObj->SetPropValue(pwsPropName, &var, CIM_STRING);
  343. return sc;
  344. }
  345. //***************************************************************************
  346. //
  347. // CIntProv::GetRegUINTProp
  348. //
  349. // Retrieves a DWORD property from the registry and puts it into the object.
  350. //
  351. //***************************************************************************
  352. SCODE CIntProv::GetRegUINTProp(Registry & reg, LPTSTR pRegValueName, LPWSTR pwsPropName,
  353. CWbemObject * pObj)
  354. {
  355. DWORD dwVal;
  356. if (reg.GetDWORDStr(pRegValueName, &dwVal))
  357. return WBEM_E_FAILED;
  358. VARIANT var;
  359. var.vt = VT_I4;
  360. var.lVal = dwVal;
  361. return pObj->Put(pwsPropName, 0, &var, 0);
  362. }
  363. //***************************************************************************
  364. //
  365. // CIntProv::PutRegStrProp
  366. //
  367. // Retrieves a string from the object and writes it to the registry.
  368. //
  369. //***************************************************************************
  370. SCODE CIntProv::PutRegStrProp(Registry & reg, LPTSTR pRegValueName, LPWSTR pwsPropName,
  371. CWbemObject * pObj)
  372. {
  373. VARIANT var;
  374. VariantInit(&var);
  375. CClearMe me(&var);
  376. SCODE sc = pObj->Get(pwsPropName, 0, &var, 0, NULL);
  377. if(sc != S_OK || var.vt != VT_BSTR)
  378. return sc;
  379. if(var.bstrVal == NULL || wcslen(var.bstrVal) < 1) // SEC:REVIEWED 2002-03-22 : OK, all known paths have provable NULL terminators
  380. {
  381. if (reg.SetStr(pRegValueName, __TEXT("")))
  382. return WBEM_E_FAILED;
  383. return S_OK;
  384. }
  385. #ifdef UNICODE
  386. TCHAR *tVal = var.bstrVal;
  387. #else
  388. int iLen = 2 * wcslen(var.bstrVal) + 1; // SEC:REVIEWED 2002-03-22 : Needs EH, but since we don't use ANSI, there is no path to this
  389. TCHAR *tVal = new TCHAR[iLen];
  390. wcstombs(tVal, var.bstrVal, iLen); // SEC:REVIEWED 2002-03-22 : Needs EH, but since we don't use ANSI, there is no path to this
  391. CDeleteMe<TCHAR> delMe(tVal);
  392. #endif
  393. if (reg.SetStr(pRegValueName, tVal))
  394. return WBEM_E_FAILED;
  395. return S_OK;
  396. }
  397. //***************************************************************************
  398. //
  399. // CIntProv::PutRegUINTProp
  400. //
  401. // Retrieves a DWORD from the object and writes it to the registry.
  402. //
  403. //***************************************************************************
  404. SCODE CIntProv::PutRegUINTProp(Registry & reg, LPTSTR pRegValueName, LPWSTR pwsPropName,
  405. CWbemObject * pObj)
  406. {
  407. CVar var;
  408. SCODE sc = pObj->Get(pwsPropName, 0, (struct tagVARIANT *)&var, 0, NULL);
  409. if(sc != S_OK || var.GetType() != VT_I4)
  410. return sc;
  411. if (reg.SetDWORDStr(pRegValueName, var.GetDWORD()))
  412. return WBEM_E_FAILED;
  413. return S_OK;
  414. }
  415. //***************************************************************************
  416. //
  417. // CIntProv::ReadAutoMofs
  418. //
  419. // Reads the autocompile list from the registry
  420. //
  421. //***************************************************************************
  422. SCODE CIntProv::ReadAutoMofs(CWbemObject * pObj)
  423. {
  424. Registry r(WBEM_REG_WINMGMT);
  425. DWORD dwSize;
  426. TCHAR * pMulti = r.GetMultiStr(__TEXT("Autorecover MOFs"), dwSize);
  427. if(pMulti == NULL)
  428. return S_OK; // Not a problem
  429. CDeleteMe<TCHAR> del1(pMulti);
  430. CSafeArray csa(VT_BSTR, CSafeArray::auto_delete); // SEC:REVIEWED 2002-03-22 : Needs EH
  431. TCHAR * pNext;
  432. int i;
  433. for(pNext = pMulti, i=0; *pNext; pNext += lstrlen(pNext) + 1, i++) // SEC:REVIEWED 2002-03-22 : OK, string from registry will have a NULL
  434. {
  435. BSTR bstr = GetBSTR(pNext);
  436. if(bstr == NULL)
  437. return WBEM_E_OUT_OF_MEMORY;
  438. csa.SetBSTRAt(i, bstr); // A copy of the BSTR is made
  439. SysFreeString(bstr);
  440. }
  441. csa.Trim();
  442. // put the data
  443. VARIANT var;
  444. var.vt = VT_BSTR | VT_ARRAY;
  445. var.parray = csa.GetArray();
  446. return pObj->Put( L"AutorecoverMofs", 0, &var, 0);
  447. }
  448. //***************************************************************************
  449. //
  450. // CIntProv::ReadLastBackup
  451. //
  452. // Gets the time of the last auto backup.
  453. //
  454. //***************************************************************************
  455. SCODE CIntProv::ReadLastBackup(Registry & reg, CWbemObject * pObj)
  456. {
  457. // Create the path to the auto backup file.
  458. LPTSTR pszData = NULL;
  459. if (reg.GetStr(__TEXT("Repository Directory"), &pszData))
  460. return WBEM_E_FAILED;
  461. CDeleteMe<TCHAR> del1(pszData);
  462. size_t tmpLength = lstrlen(pszData)+10; // SEC:REVIEWED 2002-03-22 : OK, string will have a NULL
  463. TCHAR * pFullPath = new TCHAR[tmpLength];
  464. if(pFullPath == NULL)
  465. return WBEM_E_OUT_OF_MEMORY;
  466. CDeleteMe<TCHAR> del2(pFullPath);
  467. StringCchCopy(pFullPath,tmpLength, pszData);
  468. StringCchCat(pFullPath, tmpLength, __TEXT("\\cim.rec"));
  469. BY_HANDLE_FILE_INFORMATION bh;
  470. HANDLE hFile = CreateFile(pFullPath, // SEC:REVIEWED 2002-03-22 : OK, full path is used
  471. 0, // access (read-write) mode
  472. FILE_SHARE_READ|FILE_SHARE_WRITE, // share mode
  473. NULL,
  474. OPEN_EXISTING,0, NULL);
  475. if(hFile == INVALID_HANDLE_VALUE)
  476. return S_OK;
  477. CCloseHandle cm(hFile);
  478. if(!GetFileInformationByHandle(hFile, &bh))
  479. return S_OK; // probably not a problem since the file may not exist
  480. WCHAR Date[35];
  481. SCODE sc = GetDateTime(&bh.ftLastWriteTime, false, Date, 35);
  482. if(sc != S_OK)
  483. return sc;
  484. CVar var;
  485. var.SetBSTR(Date);
  486. sc = pObj->SetPropValue(L"BackupLastTime", &var, CIM_DATETIME);
  487. return sc;
  488. }
  489. //***************************************************************************
  490. //
  491. // CIntProv::CreateWMIElementSetting
  492. //
  493. // Purpose: Creates an instance given a particular Path value.
  494. //
  495. //***************************************************************************
  496. SCODE CIntProv::CreateWMIElementSetting(IWbemClassObject FAR* FAR* ppObj, IWbemContext *pCtx)
  497. {
  498. SCODE sc;
  499. sc = CreateInstance(L"Win32_WMIElementSetting", ppObj, pCtx);
  500. if(sc != S_OK)
  501. return sc;
  502. CVar var;
  503. var.SetBSTR(L"Win32_WMISetting=@");
  504. CWbemObject * pWbemObj = (CWbemObject *)*ppObj;
  505. sc |= pWbemObj->Put(L"Setting",0, (VARIANT *)&var, 0);
  506. CVar var2;
  507. var2.SetBSTR(L"Win32_Service=\"winmgmt\"");
  508. sc |= pWbemObj->Put(L"Element",0, (VARIANT *)&var2, 0);
  509. return sc;
  510. }
  511. //***************************************************************************
  512. //
  513. // CIntProv::CreateWMISetting
  514. //
  515. // Purpose: Creates an instance given a particular Path value.
  516. //
  517. //***************************************************************************
  518. SCODE CIntProv::CreateWMISetting(IWbemClassObject FAR* FAR* ppObj, IWbemContext *pCtx)
  519. {
  520. SCODE sc, scTemp;
  521. sc = CreateInstance(L"Win32_WMISetting", ppObj, pCtx);
  522. if(sc != S_OK)
  523. return sc;
  524. // Fill in the properties
  525. Registry rWbem(HKEY_LOCAL_MACHINE, 0, KEY_READ, WBEM_REG_WBEM); // Top level wbem key
  526. Registry rCIMOM(HKEY_LOCAL_MACHINE, 0, KEY_READ, WBEM_REG_WINMGMT); // The cimom key
  527. Registry rScripting(HKEY_LOCAL_MACHINE, 0, KEY_READ, __TEXT("Software\\Microsoft\\WBEM\\scripting"));
  528. CWbemObject * pWbemObj = (CWbemObject *)*ppObj;
  529. scTemp = GetRegStrProp(rCIMOM, __TEXT("Working Directory"), L"InstallationDirectory", pWbemObj);
  530. scTemp = GetRegStrProp(rWbem, __TEXT("Build"), L"BuildVersion", pWbemObj);
  531. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Log File Max Size"), L"MaxLogFileSize", pWbemObj);
  532. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Logging"), L"LoggingLevel", pWbemObj);
  533. scTemp = GetRegStrProp(rCIMOM, __TEXT("Logging Directory"), L"LoggingDirectory", pWbemObj);
  534. scTemp = GetRegStrProp(rCIMOM, __TEXT("Repository Directory"), L"DatabaseDirectory", pWbemObj);
  535. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Max DB Size"), L"DatabaseMaxSize", pWbemObj);
  536. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Backup interval threshold"), L"BackupInterval", pWbemObj);
  537. scTemp = ReadAutoMofs(pWbemObj);
  538. scTemp = ReadLastBackup(rCIMOM, pWbemObj);
  539. DWORD dwScriptingEnabled;
  540. if(0 == rScripting.GetDWORD(__TEXT("Enable for ASP"), &dwScriptingEnabled))
  541. {
  542. CVar var;
  543. var.SetBool((dwScriptingEnabled == 0) ? VARIANT_FALSE : VARIANT_TRUE);
  544. scTemp = pWbemObj->SetPropValue(L"ASPScriptEnabled", &var, CIM_BOOLEAN);
  545. }
  546. scTemp = GetRegStrProp(rScripting, __TEXT("Default Namespace"), L"ASPScriptDefaultNamespace", pWbemObj);
  547. scTemp = GetRegUINTProp(rCIMOM, __TEXT("EnableEvents"), L"EnableEvents", pWbemObj);
  548. scTemp = GetRegUINTProp(rCIMOM, __TEXT("High Threshold On Client Objects (b)"), L"HighThresholdOnClientObjects", pWbemObj);
  549. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Low Threshold On Client Objects (b)"), L"LowThresholdOnClientObjects", pWbemObj);
  550. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Max Wait On Client Objects (ms)"), L"MaxWaitOnClientObjects", pWbemObj);
  551. scTemp = GetRegUINTProp(rCIMOM, __TEXT("High Threshold On Events (b)"), L"HighThresholdOnEvents", pWbemObj);
  552. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Low Threshold On Events (b)"), L"LowThresholdOnEvents", pWbemObj);
  553. scTemp = GetRegUINTProp(rCIMOM, __TEXT("Max Wait On Events (ms)"), L"MaxWaitOnEvents", pWbemObj);
  554. // not considered to be an error if the next one isnt there
  555. GetRegUINTProp(rCIMOM, __TEXT("LastStartupHeapPreallocation"), L"LastStartupHeapPreallocation", pWbemObj);
  556. DWORD dwEnablePreallocate = 0;
  557. rCIMOM.GetDWORD(__TEXT("EnableStartupHeapPreallocation"), &dwEnablePreallocate);
  558. CVar var;
  559. var.SetBool((dwEnablePreallocate == 1) ? VARIANT_TRUE : VARIANT_FALSE);
  560. scTemp = pWbemObj->SetPropValue(L"EnableStartupHeapPreallocation", &var, CIM_BOOLEAN);
  561. return sc;
  562. }
  563. //***************************************************************************
  564. //
  565. // CIntProv::SaveWMISetting
  566. //
  567. // Purpose: Outputs the last values back to the registry.
  568. //
  569. //***************************************************************************
  570. SCODE CIntProv::SaveWMISetting(IWbemClassObject FAR* pInst)
  571. {
  572. SCODE sc = S_OK;
  573. Registry rCIMOM(WBEM_REG_WINMGMT); // The cimom key
  574. Registry rScripting(__TEXT("Software\\Microsoft\\WBEM\\scripting"));
  575. CWbemObject * pWbemObj = (CWbemObject *)pInst;
  576. // verify that the backup interval is valid
  577. CVar var;
  578. sc = pInst->Get(L"BackupInterval", 0, (struct tagVARIANT *)&var, 0, NULL);
  579. if(sc != S_OK)
  580. return sc;
  581. if((var.GetDWORD() < 5 || var.GetDWORD() > 60*24) && var.GetDWORD() != 0)
  582. return WBEM_E_INVALID_PARAMETER;
  583. // Write the "writeable properties back into the registry
  584. sc |= PutRegUINTProp(rCIMOM, __TEXT("Backup interval threshold"), L"BackupInterval", pWbemObj);
  585. if(!IsNT())
  586. {
  587. sc |= PutRegUINTProp(rCIMOM, __TEXT("AutostartWin9X"), L"AutoStartWin9X", pWbemObj);
  588. sc = pWbemObj->Get(L"EnableAnonWin9XConnections", 0, (struct tagVARIANT *)&var, 0, NULL);
  589. if(sc == S_OK)
  590. {
  591. rCIMOM.SetDWORDStr(__TEXT("EnableAnonConnections"), var.GetBool() ? 1 : 0);
  592. }
  593. }
  594. sc |= PutRegUINTProp(rCIMOM, __TEXT("Log File Max Size"), L"MaxLogFileSize", pWbemObj);
  595. sc |= PutRegUINTProp(rCIMOM, __TEXT("Logging"), L"LoggingLevel", pWbemObj);
  596. sc |= PutRegStrProp(rCIMOM, __TEXT("Logging Directory"), L"LoggingDirectory", pWbemObj);
  597. sc |= pWbemObj->Get(L"ASPScriptEnabled", 0, (struct tagVARIANT *)&var, 0, NULL);
  598. if(sc == S_OK)
  599. {
  600. rScripting.SetDWORD(__TEXT("Enable for ASP"), var.GetBool() ? 1 : 0);
  601. }
  602. sc |= PutRegStrProp(rScripting, __TEXT("Default Namespace"), L"ASPScriptDefaultNamespace", pWbemObj);
  603. sc |= pWbemObj->Get(L"EnableEvents", 0, (struct tagVARIANT *)&var, 0, NULL);
  604. if(sc == S_OK)
  605. {
  606. rCIMOM.SetDWORDStr(__TEXT("EnableEvents"), var.GetBool() ? 1 : 0);
  607. }
  608. sc |= PutRegUINTProp(rCIMOM, __TEXT("High Threshold On Client Objects (b)"), L"HighThresholdOnClientObjects", pWbemObj);
  609. sc |= PutRegUINTProp(rCIMOM, __TEXT("Low Threshold On Client Objects (b)"), L"LowThresholdOnClientObjects", pWbemObj);
  610. sc |= PutRegUINTProp(rCIMOM, __TEXT("Max Wait On Client Objects (ms)"), L"MaxWaitOnClientObjects", pWbemObj);
  611. sc |= PutRegUINTProp(rCIMOM, __TEXT("High Threshold On Events (b)"), L"HighThresholdOnEvents", pWbemObj);
  612. sc |= PutRegUINTProp(rCIMOM, __TEXT("Low Threshold On Events (b)"), L"LowThresholdOnEvents", pWbemObj);
  613. sc |= PutRegUINTProp(rCIMOM, __TEXT("Max Wait On Events (ms)"), L"MaxWaitOnEvents", pWbemObj);
  614. sc |= pWbemObj->Get(L"EnableStartupHeapPreallocation", 0, (struct tagVARIANT *)&var, 0, NULL);
  615. if(sc == S_OK)
  616. {
  617. rCIMOM.SetDWORD(__TEXT("EnableStartupHeapPreallocation"), var.GetBool() ? 1 : 0);
  618. }
  619. return S_OK;
  620. }