1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WAD WMIQUERY

Discussion in 'Support' started by vefatica, Aug 14, 2014.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    Did you miss this one? In a thread of a couple weeks ago there's a possible explanation.

    If I ask for exactly the number of items available, I get them. If I ask for more than is available, I don't get an error message for the first failure. Starting at index 0 doesn't help (and causes the first item to be returned twice).
    Code:
    v:\> do i=1 to 7 ( echo %i & wmiquery . "SELECT StartTime from Win32_logonsession" %i )
    1
    20140611115217.443054-240
    2
    20140719191920.059415-240
    3
    20140715105813.866117-240
    4
    20140611115217.427453-240
    5
    6
    Error (SYS): Incorrect function.
    7
    Error (SYS): Incorrect function.
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,022
    Likes Received:
    84
    It's not a TCC bug.

    Not sure whether to characterize this as a WMI bug or feature. TCC queries WMI, gets an S_OK result, then calls Skip to get the next entry. That also succeeds (i.e., WMI says it's a valid entry), so TCC asks for the data and WMI returns ... nothing. (But no error, either.) TCC dutifully displays nothing, then when you try to skip to the next entry WMI returns an error, which TCC displays.

    It would be a lot easier (and actually work) if you used the /A option for WMIQUERY.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    I don't know about "S_OK", but there are other COM HRESULTs (applicable here) which (being >= 0) satisfy SUCCEEDED() and don't satisfy FAILED(), namely
    WBEM_S_FALSE (1) ... no more objects available; number returned less than requested
    WBEM_S_NO_MORE_DATA (262149) ... no more data available from an enumeration
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,022
    Likes Received:
    84
    That's all true, but WMI isn't returning any of those errors.
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    I suspect this could be overcome with quite little effort. But being in the dark, I have no specific suggestions.
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    This is a bit kludgy (a slight redesign would be more intellectually satisfying). I added testing dwReturned to my version of WMIQUERY and it does catch the condition.
    Code:
        if ( index > 1 )
           hr = pEnum->Skip(5000, index - 1);
    
         if ( hr == WBEM_S_NO_ERROR )
         {
           /* print queried properties of one or all class instances */
           while ( (hr=pEnum->Next(5000, 1, &pWbemObject, &dwReturned)) == WBEM_S_NO_ERROR || dwReturned == 0 )
           {
             if ( dwReturned == 0 )
             {
               Qprintf(STD_ERR, L"Error (TCC) Index out of range: %lu\r\n", index );
               break;
             }
    // SNIP
    
    Code:
    l:\projects\4sysutils\release> wmiquery . "SELECT * from Win32_logonsession" 2
    AuthenticationPackage = NTLM
    LogonId = 307528
    LogonType = 2
    StartTime = 20140902234359.525132-240
    
    l:\projects\4sysutils\release> wmiquery . "SELECT * from Win32_logonsession" 3
    Error (TCC) Index out of range: 3
     

Share This Page