2 Replies - 1234 Views - Last Post: 08 April 2013 - 01:27 AM Rate Topic: -----

#1 rahul007sarkar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-March 13

WMI Connect Server function is not working for Remote and Local reqs?

Posted 07 April 2013 - 06:20 AM

I am using the following function to connect to WMI & then fetch data after that:
IWbemLocator.ConnectServer()

For Local machine's WMI data I don't pass user name/password.
hres=pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
				 NULL,                    // User name. NULL = current user
				 NULL,                    // User password. NULL = current
				 0,                       // Locale. NULL indicates current
				 NULL,                    // Security flags.
				 0,                       // Authority (for example, Kerberos)
				 0,                       // Context object
				 &pSvc                    // pointer to IWbemServices proxy
				 );



For Remote machine's WMI data, I passes IP Address, username and password in the parameters of the Connect Server function.
	hres = pLoc->ConnectServer(
				_bstr_t(L"\\\\IP_Address\\root\\cimv2"),
				_bstr_t("bisadmin@torum.com"),    // User name
				_bstr_t("tytl!@#"),     // User password
				NULL,                              // Locale            
				NULL,                              // Security flags
				_bstr_t(""),// Authority       
				NULL,                              // Context object
				&pSvc                              // IWbemServices proxy
				);



But, in the second case if I pass the IP address of the local machine and its credentials, it fails to connect and gives error that User credentials cannot be used for local connections.
:dontgetit:/> So I need to 1st check whether the request is coming for Local or remote machine, and then fire the functions in two different ways as shown above. I can't use the same function for both type of requests (Local and Remote.)

Please help me if you understand my problem.
Please let me know if you want more info???

Is This A Good Question/Topic? 0
  • +

Replies To: WMI Connect Server function is not working for Remote and Local reqs?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: WMI Connect Server function is not working for Remote and Local reqs?

Posted 07 April 2013 - 06:31 PM

Why do you need to fire it in two completely two different ways, it's just a matter of setting some variables to null. In pseudo code:
if (MachineIsLocal)
{
    pszMachineName = "";
    pszUserName = NULL;
    pszPassword = NULL;
    pszAuthority = NULL;
}
else
{
    wsprintf(pszMachineName, "\\\\%s", ipaddress);
    wstrcpy(pszUserName, userName);
    wstrcpy(pszPassword, password);
    pszAuthority = "";
}

wsprintf(pszRoot, "%s\\root\\cimv2", pszMachineName);

pLoc->Connect(pszRoot, pszUserName, pszPassword, ..., pszAuthority, ...);


Was This Post Helpful? 1
  • +
  • -

#3 rahul007sarkar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-March 13

Re: WMI Connect Server function is not working for Remote and Local reqs?

Posted 08 April 2013 - 01:27 AM

Thanks it worked...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1