예제 #1
0
// run until parent process exit
bool CSessionHost::ThreadLoop()
{
	if(m_hParent == 0) 
	{
		return false;
	}
	CoInitializeEx(0,COINIT_MULTITHREADED);
	{
		CComQIPtr<IWinRobotService>pService;
		HRESULT hr = pService.CoCreateInstance(__uuidof(ServiceHost));
		if ( FAILED(hr) )
		{
			DebugOutF(filelog::log_error,"CoCreateInstance Service failed with 0x%x",hr);
			return false;
		}
		CComPtr<IWinRobotSession>pSession;
		hr = pSession.CoCreateInstance(__uuidof(WinRobotSession));
		if ( FAILED(hr) )
		{
			DebugOutF(filelog::log_error,"CoCreateInstance WinRobotSession failed with 0x%x",hr);
			return false;
		}
		CAccessToken token;
		if(!token.GetProcessToken(TOKEN_ALL_ACCESS))
		{
			DebugOutF(filelog::log_error,"GetProcessToken failed with %d",GetLastError());
			return false;
		}
		DWORD sid = 0;
		if(!token.GetTerminalServicesSessionId(&sid))
		{
			DebugOutF(filelog::log_error,"GetTerminalServicesSessionId failed with %d",GetLastError());
			return false;
		}

		pService->RegSession(sid,GetCurrentProcessId(),pSession);

		WaitForSingleObject(m_hParent,-1);
	}
	//CoUninitialize();
	return false;
}