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.

93 lines
2.5 KiB

  1. // common tools used by the various logging uis
  2. #include "stdafx.h"
  3. #include "logui.h"
  4. #include "logtools.h"
  5. //---------------------------------------------------------------
  6. // Given the class ID of a server, it goes into the registry and
  7. // sets the Apartment Model flag for that object.
  8. // The strings used here are non-localized. They are also specific
  9. // to this routine.
  10. BOOL FSetObjectApartmentModel( REFCLSID clsid )
  11. {
  12. LPOLESTR pszwSid;
  13. LONG err;
  14. HKEY hKey;
  15. // transform the clsid into a string
  16. StringFromCLSID(
  17. clsid, //CLSID to be converted
  18. &pszwSid //Address of output variable that receives a pointer to the resulting string
  19. );
  20. // put it in a cstring
  21. CString szSid = pszwSid;
  22. // free the ole string
  23. CoTaskMemFree( pszwSid );
  24. // build the registry path
  25. CString szRegPath = _T("CLSID\\");
  26. szRegPath += szSid;
  27. szRegPath += _T("\\InProcServer32");
  28. // prep the apartment name
  29. CString szApartment = _T("Apartment");
  30. // open the registry key
  31. err = RegOpenKey(
  32. HKEY_CLASSES_ROOT, // handle of open key
  33. (LPCTSTR)szRegPath, // address of name of subkey to open
  34. &hKey // address of handle of open key
  35. );
  36. if ( err != ERROR_SUCCESS )
  37. return FALSE;
  38. // set the apartment threading value
  39. err = RegSetValueEx(
  40. hKey, // handle of key to set value for
  41. _T("ThreadingModel"), // address of value to set
  42. 0, // reserved
  43. REG_SZ, // flag for value type
  44. (PBYTE)(LPCTSTR)szApartment, // address of value data
  45. (szApartment.GetLength() + 1) * sizeof(TCHAR) // size of value data
  46. );
  47. // close the registry key
  48. // in success or failure.
  49. RegCloseKey( hKey );
  50. if ( err != ERROR_SUCCESS )
  51. {
  52. return FALSE;
  53. }
  54. return TRUE;
  55. }
  56. //---------------------------------------------------------------
  57. // tests a machine name to see if it is the local machine it is
  58. // talking about
  59. BOOL FIsLocalMachine( LPCTSTR psz )
  60. {
  61. CString szLocal;
  62. DWORD cch = MAX_COMPUTERNAME_LENGTH + 1;
  63. BOOL fAnswer;
  64. // get the actual name of the local machine
  65. fAnswer = GetComputerName(szLocal.GetBuffer(cch), &cch);
  66. szLocal.ReleaseBuffer();
  67. if ( !fAnswer )
  68. return FALSE;
  69. // compare and return
  70. fAnswer = (szLocal.CompareNoCase( psz ) == 0);
  71. return fAnswer;
  72. }