Сущность технологии СОМ. Библиотека программиста   ::   Бокс Дональд

Страница: 526 из 528

up[1024];

HKEY hkey;

long err = RegOpenKeyEx(HKEY_CLASSES_ROOT,

__TEXT(«AppID\\{5223A054-2441-11d1-AF4F-0060976AA886}»),

0, KEY_QUERY_VALUE,

&hkey);

if (err == ERROR_SUCCESS)

{

DWORD cb = sizeof(wszAdminsGroup);

err = RegQueryValueExW(hkey, L"Chat Admins Group",

0, 0, (BYTE*)wszAdminsGroup,

&cb);

cb = sizeof(wszAdminsGroup);

if (err == ERROR_SUCCESS)

err = RegQueryValueExW(hkey,

L"Chat Users Group",

0, 0, (BYTE*)wszUsersGroup,

&cb);

RegCloseKey(hkey);

}

if (err != ERROR_SUCCESS)

return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32,

GetLastError());

// declare vectors of user/groups for 2 access

// control objects

ACTRL_ACCESS_ENTRYW rgaaeUsers[] = {

{ {0, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_NAME,

TRUSTEE_IS_GROUP, wszUsersGroup },

ACTRL_ACCESS_ALLOWED, COM_RIGHTS_EXECUTE, 0,

NO_INHERITANCE, 0 },

};

ACTRL_ACCESS_ENTRY_LISTW aaelUsers = {

sizeof(rgaaeUsers)/sizeof(*rgaaeUsers),

rgaaeUsers

};

ACTRL_PROPERTY_ENTRYW apeUsers = { 0, &aaelUsers, 0 };

ACTRL_ACCESSW aaUsers = { 1, &apeUsers };

ACTRL_ACCESS_ENTRYW rgaaeAdmins[] = {

{ {0, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_NAME,

TRUSTEE_IS_GROUP, wszAdminsGroup },

ACTRL_ACCESS_ALLOWED, COM_RIGHTS_EXECUTE, 0,

NO_INHERITANCE, 0 },

};

ACTRL_ACCESS_ENTRY_LISTW aaelAdmins = {

sizeof(rgaaeAdmins)/sizeof(*rgaaeAdmins),

rgaaeAdmins

};

ACTRL_PROPERTY_ENTRYW apeAdmins = { 0, &aaelAdmins, 0 };

ACTRL_ACCESSW aaAdmins = { 1, &apeAdmins };

HRESULT hr = CoInitializeSecurity(0, -1, 0, 0,

RPC_C_AUTHN_LEVEL_NONE,

RPC_C_IMP_LEVEL_ANONYMOUS,

0,

EOAC_NONE,

0);

if (SUCCEEDED(hr))

{

hr = CoCreateInstance(CLSID_DCOMAccessControl,

0, CLSCTX_ALL, IID_IAccessControl,

(void**)&g_pacUsers);

if (SUCCEEDED(hr))

hr = g_pacUsers->SetAccessRights(&aaUsers);

if (SUCCEEDED(hr))

{

hr = CoCreateInstance(CLSID_DCOMAccessControl,

0, CLSCTX_ALL,

IID_IAccessControl,

(void**)&g_pacAdmins);

if (SUCCEEDED(hr))

hr = g_pacAdmins->SetAccessRights(&aaAdmins);

}

if (FAILED(hr))

{

if (g_pacAdmins)

{

g_pacAdmins->Release();

g_pacAdmins = 0;

}

if (g_pacUsers)

{

g_pacUsers->Release();

g_pacUsers = 0;

}

}

}

return hr;

}

// the main thread routine that simply registers the class

// object and waits to die

int WINAPI WinMain(HINSTANCE, HINSTANCE,

LPSTR szCmdParam, int)

{

const TCHAR *pszPrompt =

__TEXT("Ensure that you have properly ")

__TEXT("configured the application to ")

__TEXT("run as a particular user and that ")

__TEXT("you have manually changed the ")

__TEXT("Users and Admins Group registry ")

__TEXT(«settings under this server's AppID.»);

HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);

if (FAILED(hr))

return hr;

// look for self-registration flags

if (strstr(szCmdParam, «/UnregServer») != 0

|| strstr(szCmdParam, «-UnregServer») != 0)

{

hr = UnregisterServer();

CoUninitialize();

return hr;

}

else if (strstr(szCmdParam, «/RegServer») != 0

|| strstr(szCmdParam, «-RegServer») != 0)

{

hr = RegisterServer();

MessageBox(0, pszPrompt, __TEXT(«COMChat»),

MB_SETFOREGROUND);

CoUninitialize();

return hr;

}

// set up process security

hr = InitializeApplicationSecurity();

if (SUCCEEDED(hr))

{

// register class object and wait to die

DWORD dwReg;

static ChatSessionClass cmc;

hr = CoRegisterClassObject(CLSID_ChatSession,

static_cast(&cmc),

CLSCTX_LOCAL_SERVER

REGCLS_SUSPENDED|REGCLS_MULTIPLEUSE,

&dwReg);

if (SUCCEEDED(hr))

{

hr = CoResumeClassObjects();

if (SUCCEEDED(hr))

WaitForSingleObject(g_heventDone, INFINITE);

CoRevokeClassObject(dwReg);

}

g_

|< Пред. 524 525 526 527 528 След. >|

Java книги

Контакты: [email protected]