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.

94 lines
2.4 KiB

  1. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  2. #include "precomp.h"
  3. #include <stdio.h>
  4. #include "reg.h"
  5. // Function pointer type used with LoadMofFiles entrypoint in wbemupgd.dll
  6. typedef BOOL ( WINAPI *PFN_LOAD_MOF_FILES )(wchar_t* pComponentName, const char* rgpszMofFilename[]);
  7. HRESULT SetSNMPBuildRegValue();
  8. BOOL WINAPI DllMain( IN HINSTANCE hModule,
  9. IN ULONG ul_reason_for_call,
  10. LPVOID lpReserved
  11. )
  12. {
  13. return TRUE;
  14. }
  15. //***************************************************************************
  16. //
  17. // DllRegisterServer
  18. //
  19. // Purpose: Called during setup to perform various setup tasks
  20. // (This is not the normal use of DllRegisterServer!)
  21. //
  22. // Return: NOERROR
  23. //***************************************************************************
  24. STDAPI DllRegisterServer(void)
  25. {
  26. // load the MOF files for this component
  27. HRESULT hr = NOERROR;
  28. HINSTANCE hinstWbemupgd = LoadLibraryW(L"wbemupgd.dll");
  29. if (hinstWbemupgd)
  30. {
  31. PFN_LOAD_MOF_FILES pfnLoadMofFiles = (PFN_LOAD_MOF_FILES) GetProcAddress(hinstWbemupgd, "LoadMofFiles"); // no wide version of GetProcAddress
  32. if (pfnLoadMofFiles)
  33. {
  34. wchar_t* wszComponentName = L"SNMP Provider";
  35. const char* rgpszMofFilename[] =
  36. {
  37. "snmpsmir.mof",
  38. "snmpreg.mof",
  39. NULL
  40. };
  41. if (!pfnLoadMofFiles(wszComponentName, rgpszMofFilename))
  42. {
  43. hr = E_FAIL;
  44. }
  45. }
  46. else
  47. {
  48. hr = HRESULT_FROM_WIN32(GetLastError());
  49. }
  50. FreeLibrary(hinstWbemupgd);
  51. }
  52. else
  53. {
  54. hr = HRESULT_FROM_WIN32(GetLastError());
  55. }
  56. if (SUCCEEDED(hr))
  57. {
  58. SetSNMPBuildRegValue(); // set SNMP build number in registry
  59. }
  60. return hr;
  61. }
  62. HRESULT SetSNMPBuildRegValue()
  63. {
  64. Registry r(WBEM_REG_WBEM);
  65. if (r.GetStatus() != Registry::no_error)
  66. {
  67. return E_FAIL;
  68. }
  69. char* pszBuildNo = new char[10];
  70. OSVERSIONINFO os;
  71. os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  72. if(GetVersionEx(&os))
  73. {
  74. sprintf(pszBuildNo, "%lu.0000", os.dwBuildNumber);
  75. }
  76. r.SetStr("SNMP Build", pszBuildNo);
  77. delete [] pszBuildNo;
  78. return NOERROR;
  79. }