Now I am writing a WMI query utility following the examples provided in this link: http://msdn.microsoft.com/en-us/library/windows/desktop/aa390422(v=vs.85).aspx
But I find that the program may blocking on the call to IWbemLocator::ConnectServer. Here is the code:
hres = pLoc->ConnectServer(
_bstr_t(L"\\\\COMPUTERNAME\\root\\cimv2"),
_bstr_t(useToken?NULL:pszName), // User name
_bstr_t(useToken?NULL:pszPwd), // User password
NULL, // Locale
NULL, // Security flags
_bstr_t(useNTLM?NULL:pszAuthority),// Authority
NULL, // Context object
&pSvc // IWbemServices proxy
);
My question is how can I set a time out option, before calling IWbemLocator::ConnectServer
.
As per the ConnectServer
method description, setting the lSecurityFlags parameter to WBEM_FLAG_CONNECT_USE_MAX_WAIT
enforces a 2 minute timeout. Looks like there's no way to set a custom timeout though.