Click here to Skip to main content
Sign Up to vote bad
good
See more: C++WMI
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:
 

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 5 Nov '12 - 0:32
bitov27630


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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Mohammed Hameed 268
1 OriginalGriff 261
2 Sergey Alexandrovich Kryukov 178
3 Mayur_Panchal 153
4 Santhosh G_ 108
0 Sergey Alexandrovich Kryukov 8,171
1 OriginalGriff 6,246
2 CPallini 3,532
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid