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); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)