WMI -

I am implementing WMI in Driver.Through wmi communication is done. driver write data in wmi. GUI reads data from wmi. datatype taken in WMI( MOF file) is string type. if there is one variable i am able to write data in string and read from GUI. but if more than 1 variable of string type is there i am not able to retreive value of second string variable. apart from string datatype int variable access is fine.

eg:
class A
{
[WmiDataId(1), Read]
string Version[128];

[WmiDataId(2), Read]
string IP[48];

}

so from driver i am writing value of version and IP. so only version value is updated in WMI. IP value is null. if i change order of IP and version i will receive value of IP but version changes to null.

I’ve defined WMI records with multiple string embers many times. I always specify the qualifier MaxLen (see https://msdn.microsoft.com/en-us/library/windows/hardware/ff566365(v=vs.85).aspx), which causes the record definition to have a fixed size buffer. When you store the string, you then need to set the first wchar to the string length, and I usually zero fill the rest of the buffer. This strategy probably doesn’t work if you want to return multiple very large strings. It still might be possible to return multiple large strings, but the offset in the record becomes dynamic, and you will need to get WMI to dynamically allocate the buffer. If you just declare a string member in a record with no MaxLen qualifier, as I remember you just get a single wchar of space allocated, probably because you’re expected to store the length in this slot and then cope with the dynamic space needed for the variable size value.

Also note, if it’s an NDIS driver, the Microsoft driver certifications test scripts can’t cope with multiple string members in WMI records in some cases. The only solution I found to passing the tests was to move my extra strings to methods, out of the record field definition.

The two fields you define below should easily be handled by fixed buffer allocations with the MaxLen qualifier.

Jan

On 4/7/16, 5:16 AM, “xxxxx@lists.osr.com on behalf of xxxxx@gmail.com” wrote:

>eg:
>class A
>{
> [WmiDataId(1), Read]
> string Version[128];
>
> [WmiDataId(2), Read]
> string IP[48];
>
>}
>
>so from driver i am writing value of version and IP. so only version value is updated in WMI. IP value is null. if i change order of IP and version i will receive value of IP but version changes to null.
>
>—
>NTDEV is sponsored by OSR
>
>Visit the list online at: http:
>
>MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>Details at http:
>
>To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

thanks Jan Bottorff for your quick reply.

in my code i had taken maxlen

[WmiDataId(1), Read, Write, MaxLen(128), Description(“Version”)]
string Version;

[WmiDataId(2), Read, Write, MaxLen(128), Description(“IP”)]
string IP;

so second string i am unable to send from Driver to GUI. i will try the method suggested by you to dynamically allocate the memory.

You need to put the maximum string length in the first word of the string buffer, and then zero fill/terminate the string in the buffer, in Unicode.

To return values, the buffer initially given to you may not be large enough, in which case you need to set the field (don’t off the top of my head remember it’s name) and return the correct error. The OS will then call you again with a buffer at least as large as you requested.

One of the sample drivers does all this.

Jan

On 4/13/16, 11:46 PM, “xxxxx@lists.osr.com on behalf of xxxxx@gmail.com” wrote:

>thanks Jan Bottorff for your quick reply.
>
>in my code i had taken maxlen
>
>[WmiDataId(1), Read, Write, MaxLen(128), Description(“Version”)]
> string Version;
>
>[WmiDataId(2), Read, Write, MaxLen(128), Description(“IP”)]
> string IP;
>
>so second string i am unable to send from Driver to GUI. i will try the method suggested by you to dynamically allocate the memory.
>
>—
>NTDEV is sponsored by OSR
>
>Visit the list online at: http:
>
>MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>Details at http:
>
>To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>