ConnectServer() API gets fail in Windows XP PE  
Author Message
anisk





PostPosted: Visual C++ Language, ConnectServer() API gets fail in Windows XP PE Top

hi,

Why ConnectServer() API gets fail in Windows XP PE

This there any changes to be done or some kind of setting to get this API successful.



Visual C++16  
 
 
Marius Bancila





PostPosted: Visual C++ Language, ConnectServer() API gets fail in Windows XP PE Top

Are you talking about shi ConnectServer() function

HRESULT ConnectServer(
  const BSTR strNetworkResource,
  const BSTR strUser,
  const BSTR strPassword,
  const BSTR strLocale,
  LONG lSecurityFlags,
  const BSTR strAuthority,
  IWbemContext* pCtx,
  IWbemServices** ppNamespace
);

Did you try to check the return value

This method returns an HRESULT that indicates the status of the method call. The following table describes the value contained within an HRESULT.

COM-specific error codes may be returned if network problems cause you to lose the remote connection to Windows Management.

These error return codes are defined in the Wbemcli.h file in the WMI section of the PSDK \Include directory. For more information see WMI Error Constants.



 
 
anisk





PostPosted: Visual C++ Language, ConnectServer() API gets fail in Windows XP PE Top

As of i'm checking the error with the switch for every possible error but it is going into default... ithink i'm going some where wrong ...

here is the code

hRes = pIWbemLocator->ConnectServer(

bstrNamespace, // Namespace

NULL, // Userid

NULL, // PW

NULL, // Locale

0, // flags

NULL, // Authority

NULL, // Context

&m_pWbemServices

);

if (FAILED(hRes))

{

switch(hRes)

{

case WBEM_E_INVALID_NAMESPACE:

AfxMessageBox("WBEM_E_INVALID_NAMESPACE");

break;

case WBEM_E_ACCESS_DENIED:

AfxMessageBox("WBEM_E_ACCESS_DENIED");

break;

case WBEM_E_FAILED:

AfxMessageBox("WBEM_E_FAILED");

break;

case WBEM_E_INVALID_PARAMETER:

AfxMessageBox("WBEM_E_INVALID_PARAMETER");

break;

case WBEM_E_TRANSPORT_FAILURE:

AfxMessageBox("WBEM_E_TRANSPORT_FAILURE");

break;

case WBEM_E_LOCAL_CREDENTIALS:

AfxMessageBox("WBEM_E_LOCAL_CREDENTIALS");

break;

case WBEM_E_OUT_OF_MEMORY:

AfxMessageBox("WBEM_E_OUT_OF_MEMORY");

break;

default:

AfxMessageBox("ConnectServer API Failed");

break;

}

pIWbemLocator->Release();

return FALSE;

}


 
 
Marius Bancila





PostPosted: Visual C++ Language, ConnectServer() API gets fail in Windows XP PE Top

In this case, get the numeric value of error code and look-up in the complete list of WMI error codes, perhaps you can find it.