Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi! I need connect to remote desktop. I decided using wmi. But I've got an error - RPC server is unavailable. But my server is really exist and really work. Can anybody help me? My source:


C++
void ConnectToServer()
{
	HRESULT  hr =  CoInitializeEx(0, COINIT_MULTITHREADED);
	
	if (SUCCEEDED(hr))
	{
		// Initialize Security
		hr =  CoInitializeSecurity(
			NULL,
			-1,      // COM negotiates service
			NULL,    // Authentication services
			NULL,    // Reserved
			RPC_C_AUTHN_LEVEL_PKT_PRIVACY,    // authentication
			RPC_C_IMP_LEVEL_IMPERSONATE,  // Impersonation
			NULL,             // Authentication info
			EOAC_NONE,        // Additional capabilities
			NULL              // Reserved
			);
	}
	 
	IWbemLocator *pLocator = NULL;
	if (SUCCEEDED(hr))
	{
		// Obtain the initial locator to Windows Management
		// on a particular host computer.
		hr = CoCreateInstance(
			CLSID_WbemLocator,
			0,
			CLSCTX_INPROC_SERVER,
			IID_IWbemLocator, (LPVOID *) &pLocator);
	}

	IWbemServices *pNamespace = NULL; 
	 
	BSTR strNetworkResource = SysAllocString(L"\\\\109.87.254.211\\root\\default");
	 
	BSTR bstrUserName = SysAllocString(L"mylogin");
	BSTR bstrPassword = SysAllocString(L"mypassword"); 

	if (SUCCEEDED(hr))
	{
		 
		hr = pLocator->ConnectServer(
			strNetworkResource,               // WMI namespace
			bstrUserName,                       // User name
			bstrPassword,                       // User password
			0,                            // Locale
			NULL,                       // Security flags
			0,                            // Authority
			0,                            // Context object
			&pNamespace     // IWbemServices proxy
			);
	}

	

	if(SUCCEEDED(hr))
	{
		 
		AfxMessageBox(L"Connection success");
	}
	else
	{   
		AfxMessageBox(L"Connection failed");
	}

	SysFreeString(bstrUserName);
	SysFreeString(bstrPassword);
	SysFreeString(strNetworkResource); 
	 
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900