WMI - 3 days it made me really mad:(

Hi Everybody,

While trying to implement WMI in one of my projects, faced a really though problem (at least for me - a WMI beginner) I have been trying to figure it out, for 3 days. So asking was the last resort:<

Problem is as follows:
1.I dont have an AddDevice routine, I create my device in DriverEntry.
2.Upon user request via DeviceIoControl, Driver registers to WMI like the line below:
IoWMIRegistrationControl(DriverObject->DeviceObject,WMIREG_ACTION_REGISTER);
3.Every structure is initialized correctly (WMILIB_CONTEXT,GUIDLIST etc.) And I use BASENAME for my instances, so no PDO…
4.F?nally deregistering from WMI with WMIREG_ACTION_DEREGISTER. (DriverUnload routine)

After performing the 2nd step, I think I should be able to see my WMI CLASS name in WMI EXPLORER utilities, but I AM NOT ABLE TO??? I also try to connect to the “root\WMI:class” programatically but it errs to… What should I do to successfully register my CLASS to root\WMI namespace? (source code below)

ANY HELP IS APPRECIATED,
THANKS

Full source code is here:

//MOF RESOURCE FILE
#include <windows.h>
LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
MofResource MOFDATA wmi42.bmf
//--------------------------------------------

//MOF FILE
[Dynamic, Provider(“WMIProv”),
WMI,
Description(“Wmi42 Sample Schema”),
guid(“ACF28F39-88C5-4019-BD87-C695ED44C98B”)]

class Wmi42
{
[key, read]
string InstanceName;

[read] boolean Active;

[WmiDataId(1),Description(“Some Question”)]
uint32 TheAnswer;

[WmiDataId(2),
read, write,
DisplayName(“BOOLEAN”) : amended,
Description(“boolean data”) : amended]
boolean Xboolean;

[WmiDataId(3),
read, write,
DisplayName(“UCHAR”) : amended,
Description(“unsigned character data”) : amended]
uint8 Xuint8;

[WmiDataId(4),
read, write,
DisplayName(“USHORT”) : amended,
Description(“unsigned short data”) : amended]
uint16 Xuint16;
};
//----------------------------------------------------------------------------------

//Here is WMI header file
//WMI.H--------------------
#include “wmilib.h”
#include “wmistr.h”

// Wmi42 Sample Schema
static GUID Wmi42_GUID = {0xacf28f39,0x88c5,0x4019,0xbd,0x87,0xc6,0x95,0xed,0x44,0xc9,0x8b} ;

typedef struct _Wmi42
{
// The Answer to the Ultimate Question
ULONG TheAnswer;
#define Wmi42_TheAnswer_SIZE sizeof(ULONG)
#define Wmi42_TheAnswer_ID 1

// boolean data
BOOLEAN Xboolean;
#define Wmi42_Xboolean_SIZE sizeof(BOOLEAN)
#define Wmi42_Xboolean_ID 2

// unsigned character data
UCHAR Xuint8;
#define Wmi42_Xuint8_SIZE sizeof(UCHAR)
#define Wmi42_Xuint8_ID 3

// unsigned short data
USHORT Xuint16;
#define Wmi42_Xuint16_SIZE sizeof(USHORT)
#define Wmi42_Xuint16_ID 4

} Wmi42, PWmi42;

#define Wmi42_SIZE (FIELD_OFFSET(Wmi42, Xuint16) + Wmi42_Xuint16_SIZE)

//WMI FUNCTIONS
//##########################################################################################################3
NTSTATUS WmiQueryReginfo(PDEVICE_OBJECT fdo, PULONG flags,PUNICODE_STRING instname, PUNICODE_STRING
regpath,PUNICODE_STRING resname, PDEVICE_OBJECT* pdo){
*flags = WMIREG_FLAG_INSTANCE_BASENAME;
*regpath = &driverRegKey;

RtlInitUnicodeString(resname, L"MofResource");
static WCHAR basename = L"WMIEXTRA";
instname->Buffer = (PWCHAR) ExAllocatePool(PagedPool,
sizeof(basename));
if (!instname->Buffer){
DbgPrint(“INSUFFICIENT WmiQueryReginfo”);
return STATUS_INSUFFICIENT_RESOURCES;
}
instname->MaximumLength = sizeof(basename);
instname->Length = sizeof(basename) - 2;
RtlCopyMemory(instname->Buffer, basename, sizeof(basename));
DbgPrint(“SUCCESS WmiQueryReginfo”);
return STATUS_SUCCESS;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiQueryDataBlock(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG InstanceCount,IN OUT PULONG InstanceLengthArray,IN ULONG BufferAvail,OUT PUCHAR Buffer){
DbgPrint(“WmiQueryDataBlock”);
NTSTATUS status = STATUS_SUCCESS;
PWmi42 pvalue = (PWmi42) Buffer;
pvalue->TheAnswer = 0xE;
InstanceLengthArray[0] = Wmi42_SIZE;

return WmiCompleteRequest(DeviceObject, Irp, STATUS_SUCCESS,Wmi42_SIZE, IO_NO_INCREMENT);
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiSetDataBlock(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG BufferSize,IN PUCHAR Buffer){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiSetDataBlock”);
return status;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiSetDataItem(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG DataItemId,IN ULONG BufferSize,IN PUCHAR Buffer){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiSetDataItem”);
return status;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiExecuteMethod(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG MethodId,IN ULONG InBufferSize,IN ULONG OutBufferSize,IN OUT PUCHAR Buffer){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiExecuteMethod”);
return status;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiFunctionControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN WMIENABLEDISABLECONTROL Function,IN BOOLEAN Enable){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiFunctionControl”);
return status;
}
//##########################################################################################################3

//##############################################################################################################
WMIGUIDREGINFO guidlist = {
{&Wmi42_GUID, 1, 0},
};
//##############################################################################################################

//##############################################################################################################
WMILIB_CONTEXT wmiContext = {
1,//arraysize(guidlist)
guidlist,
WmiQueryReginfo,
WmiQueryDataBlock,
NULL,//WmiSetDataBlock,
NULL,//WmiSetDataItem,
NULL,//WmiExecuteMethod,
NULL,//WmiFunctionControl,
};
//##############################################################################################################

//##############################################################################################################
typedef struct _WMI{
ULONG_PTR ProviderId;
PVOID DataPath;
ULONG BufferSize;
PVOID Buffer;
} WMI,*PWMI;
WMI wmi;
//============================================================================================================
//WMI ile ilgili olan DISPATCH FUNC burada!
NTSTATUS SUR32SystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
SYSCTL_IRP_DISPOSITION irpStatus;
NTSTATUS status;
PIO_STACK_LOCATION pIO = IoGetCurrentIrpStackLocation(Irp);

DbgPrint(“MINOR FUNCTION : %x”,(DWORD)pIO->MinorFunction);
status = WmiSystemControl(&wmiContext,DeviceObject,Irp,&irpStatus);
DbgPrint(“WmiSystemControl Returns : %x”,(DWORD)status);

//?imdi IRP’nin durumunu kontrol ve ona g?re gerekeni yap!
switch (irpStatus)
{
case IrpProcessed:
DbgPrint(“IrpProcessed”);
break;
case IrpNotCompleted:
DbgPrint(“IrpNotCompleted %x”,(DWORD)Irp->IoStatus.Status);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
break;
default:
case IrpNotWmi:
case IrpForward:
DbgPrint(“IrpNotWmi IrpForward”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
break;
}

return STATUS_SUCCESS;
}

//============================================================================================================</windows.h>

Where are your is MOF structure? Is it embedded in your RC file, or is an array in your image?

–Mark Cariddi
OSR, Open System Resources, Inc
Technical Fellha

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Sunday, September 12, 2010 4:06 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] WMI - 3 days it made me really mad:(

Hi Everybody,

While trying to implement WMI in one of my projects, faced a really though problem (at least for me - a WMI beginner) I have been trying to figure it out, for 3 days. So asking was the last resort:<

Problem is as follows:
1.I dont have an AddDevice routine, I create my device in DriverEntry.
2.Upon user request via DeviceIoControl, Driver registers to WMI like the line below:
IoWMIRegistrationControl(DriverObject->DeviceObject,WMIREG_ACTION_REGISTER);
3.Every structure is initialized correctly (WMILIB_CONTEXT,GUIDLIST etc.) And I use BASENAME for my instances, so no PDO…
4.F?nally deregistering from WMI with WMIREG_ACTION_DEREGISTER. (DriverUnload routine)

After performing the 2nd step, I think I should be able to see my WMI CLASS name in WMI EXPLORER utilities, but I AM NOT ABLE TO??? I also try to connect to the “root\WMI:class” programatically but it errs to… What should I do to successfully register my CLASS to root\WMI namespace? (source code below)

ANY HELP IS APPRECIATED,
THANKS

Full source code is here:

//MOF RESOURCE FILE
#include <windows.h>
LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
MofResource MOFDATA wmi42.bmf
//--------------------------------------------

//MOF FILE
[Dynamic, Provider(“WMIProv”),
WMI,
Description(“Wmi42 Sample Schema”),
guid(“ACF28F39-88C5-4019-BD87-C695ED44C98B”)]

class Wmi42
{
[key, read]
string InstanceName;

[read] boolean Active;

[WmiDataId(1),Description(“Some Question”)]
uint32 TheAnswer;

[WmiDataId(2),
read, write,
DisplayName(“BOOLEAN”) : amended,
Description(“boolean data”) : amended]
boolean Xboolean;

[WmiDataId(3),
read, write,
DisplayName(“UCHAR”) : amended,
Description(“unsigned character data”) : amended]
uint8 Xuint8;

[WmiDataId(4),
read, write,
DisplayName(“USHORT”) : amended,
Description(“unsigned short data”) : amended]
uint16 Xuint16;
};
//----------------------------------------------------------------------------------

//Here is WMI header file
//WMI.H--------------------
#include “wmilib.h”
#include “wmistr.h”

// Wmi42 Sample Schema
static GUID Wmi42_GUID = {0xacf28f39,0x88c5,0x4019,0xbd,0x87,0xc6,0x95,0xed,0x44,0xc9,0x8b} ;

typedef struct _Wmi42
{
// The Answer to the Ultimate Question
ULONG TheAnswer;
#define Wmi42_TheAnswer_SIZE sizeof(ULONG)
#define Wmi42_TheAnswer_ID 1

// boolean data
BOOLEAN Xboolean;
#define Wmi42_Xboolean_SIZE sizeof(BOOLEAN)
#define Wmi42_Xboolean_ID 2

// unsigned character data
UCHAR Xuint8;
#define Wmi42_Xuint8_SIZE sizeof(UCHAR)
#define Wmi42_Xuint8_ID 3

// unsigned short data
USHORT Xuint16;
#define Wmi42_Xuint16_SIZE sizeof(USHORT)
#define Wmi42_Xuint16_ID 4

} Wmi42, PWmi42;

#define Wmi42_SIZE (FIELD_OFFSET(Wmi42, Xuint16) + Wmi42_Xuint16_SIZE)

//WMI FUNCTIONS
//##########################################################################################################3
NTSTATUS WmiQueryReginfo(PDEVICE_OBJECT fdo, PULONG flags,PUNICODE_STRING instname, PUNICODE_STRING
regpath,PUNICODE_STRING resname, PDEVICE_OBJECT* pdo){
*flags = WMIREG_FLAG_INSTANCE_BASENAME;
*regpath = &driverRegKey;

RtlInitUnicodeString(resname, L"MofResource");
static WCHAR basename = L"WMIEXTRA";
instname->Buffer = (PWCHAR) ExAllocatePool(PagedPool,
sizeof(basename));
if (!instname->Buffer){
DbgPrint(“INSUFFICIENT WmiQueryReginfo”);
return STATUS_INSUFFICIENT_RESOURCES;
}
instname->MaximumLength = sizeof(basename);
instname->Length = sizeof(basename) - 2;
RtlCopyMemory(instname->Buffer, basename, sizeof(basename));
DbgPrint(“SUCCESS WmiQueryReginfo”);
return STATUS_SUCCESS;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiQueryDataBlock(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG InstanceCount,IN OUT PULONG InstanceLengthArray,IN ULONG BufferAvail,OUT PUCHAR Buffer){
DbgPrint(“WmiQueryDataBlock”);
NTSTATUS status = STATUS_SUCCESS;
PWmi42 pvalue = (PWmi42) Buffer;
pvalue->TheAnswer = 0xE;
InstanceLengthArray[0] = Wmi42_SIZE;

return WmiCompleteRequest(DeviceObject, Irp, STATUS_SUCCESS,Wmi42_SIZE, IO_NO_INCREMENT);
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiSetDataBlock(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG BufferSize,IN PUCHAR Buffer){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiSetDataBlock”);
return status;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiSetDataItem(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG DataItemId,IN ULONG BufferSize,IN PUCHAR Buffer){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiSetDataItem”);
return status;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiExecuteMethod(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN ULONG InstanceIndex,IN ULONG MethodId,IN ULONG InBufferSize,IN ULONG OutBufferSize,IN OUT PUCHAR Buffer){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiExecuteMethod”);
return status;
}
//##########################################################################################################3

//##########################################################################################################3
NTSTATUS WmiFunctionControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN ULONG GuidIndex,IN WMIENABLEDISABLECONTROL Function,IN BOOLEAN Enable){
NTSTATUS status = STATUS_SUCCESS;
DbgPrint(“WmiFunctionControl”);
return status;
}
//##########################################################################################################3

//##############################################################################################################
WMIGUIDREGINFO guidlist = {
{&Wmi42_GUID, 1, 0},
};
//##############################################################################################################

//##############################################################################################################
WMILIB_CONTEXT wmiContext = {
1,//arraysize(guidlist)
guidlist,
WmiQueryReginfo,
WmiQueryDataBlock,
NULL,//WmiSetDataBlock,
NULL,//WmiSetDataItem,
NULL,//WmiExecuteMethod,
NULL,//WmiFunctionControl,
};
//##############################################################################################################

//##############################################################################################################
typedef struct _WMI{
ULONG_PTR ProviderId;
PVOID DataPath;
ULONG BufferSize;
PVOID Buffer;
} WMI,*PWMI;
WMI wmi;
//============================================================================================================
//WMI ile ilgili olan DISPATCH FUNC burada!
NTSTATUS SUR32SystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { SYSCTL_IRP_DISPOSITION irpStatus; NTSTATUS status; PIO_STACK_LOCATION pIO = IoGetCurrentIrpStackLocation(Irp);

DbgPrint(“MINOR FUNCTION : %x”,(DWORD)pIO->MinorFunction); status = WmiSystemControl(&wmiContext,DeviceObject,Irp,&irpStatus);
DbgPrint(“WmiSystemControl Returns : %x”,(DWORD)status);

//?imdi IRP’nin durumunu kontrol ve ona gvre gerekeni yap!
switch (irpStatus)
{
case IrpProcessed:
DbgPrint(“IrpProcessed”);
break;
case IrpNotCompleted:
DbgPrint(“IrpNotCompleted %x”,(DWORD)Irp->IoStatus.Status);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
break;
default:
case IrpNotWmi:
case IrpForward:
DbgPrint(“IrpNotWmi IrpForward”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
break;
}

return STATUS_SUCCESS;
}

//============================================================================================================

—
NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</windows.h>

Thanks for the reply,mof structure is in wmi42.mof file and its compiled with mofcomp (VS2008 pre-build) and added as a resource to the project (first file above). I am not using the mof file in the project,only using the BMF file and auto-generated header file. When i look at the resulting driver file, i can see the embedded MOFRESOURCE in RSRC Section. Thanks

Are you receiving a call asking for your list of WMI GUIDS?

–Mark Cariddi

BTW, have you looked at the WMI example on OSRONLINE that uses the NOTHING driver? There are articles there also…

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, September 13, 2010 10:43 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WMI - 3 days it made me really mad:(

Thanks for the reply,mof structure is in wmi42.mof file and its compiled with mofcomp (VS2008 pre-build) and added as a resource to the project (first file above). I am not using the mof file in the project,only using the BMF file and auto-generated header file. When i look at the resulting driver file, i can see the embedded MOFRESOURCE in RSRC Section. Thanks


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

In response to IoWMIRegistrationControl, system calls my SUR32SystemControl dispatch routine. Inside this routine,i call WmiSystemControl with WMILIB_CONTEXT which includes my WMIGUIDREGINFO,which in turn calls my WmiQueryRegInfo routine,yes it wants a GUID list. Completing this stage, when i check SYSCTL_IRP_DISPOSITION ,it says IrpNotCompleted. According to DDK, this shows that an IRP_MN_REGINFO_EX has arrived or AN ERROR. Return values and irp status shows Success. Every step works,i can see that with dbgprinted messages,but the last step above which tells about ‘AN ERROR’ made me think! I think its more clear now. Again thanks Mr.Mark for helping. BTW, this is a mix of OSR NOTHING and W.ONEY WMI42.

Well, I have no idea what Walter’s code does, but I do know that the NOTHING driver worked last time I checked. So I guess you are going to have to figure out how your driver and the NOTHING driver differ. Have you stepped through the Nothing driver to see how it responds?

–Mark Cariddi
OSR Open Systems Resources, Inc.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, September 13, 2010 12:55 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WMI - 3 days it made me really mad:(

In response to IoWMIRegistrationControl, system calls my SUR32SystemControl dispatch routine. Inside this routine,i call WmiSystemControl with WMILIB_CONTEXT which includes my WMIGUIDREGINFO,which in turn calls my WmiQueryRegInfo routine,yes it wants a GUID list. Completing this stage, when i check SYSCTL_IRP_DISPOSITION ,it says IrpNotCompleted. According to DDK, this shows that an IRP_MN_REGINFO_EX has arrived or AN ERROR. Return values and irp status shows Success. Every step works,i can see that with dbgprinted messages,but the last step above which tells about ‘AN ERROR’ made me think! I think its more clear now. Again thanks Mr.Mark for helping. BTW, this is a mix of OSR NOTHING and W.ONEY WMI42.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I think only difference between my code,and Nothing is , I DONT HAVE AN ADDDEVICE ROUTINE, and i am NOT attaching to any device stack. As far as i know, there is no relation between.IS IT REQUIRED TO ATTACH TO SOME DEVICE STACK,IN ORDER TO USE WMI? coz,as i said, i only have a FDO. No FiDO,PDO… If yes,which stack should i attach? If it succeeds,it will be root/wmi:WMI42,right.

you should be able to implement a wmi provider in a nonpnp/legacy driver just fine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, September 13, 2010 10:58 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WMI - 3 days it made me really mad:(

I think only difference between my code,and Nothing is , I DONT HAVE AN ADDDEVICE ROUTINE, and i am NOT attaching to any device stack. As far as i know, there is no relation between.IS IT REQUIRED TO ATTACH TO SOME DEVICE STACK,IN ORDER TO USE WMI? coz,as i said, i only have a FDO. No FiDO,PDO… If yes,which stack should i attach? If it succeeds,it will be root/wmi:WMI42,right.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks Mr. DORON,I even changed device flags to !exclusive,but no way out:( source is as above, it looks fine and no errors but ???

Maybe you have a flag of “use PDO name as WMI instance name”? this will not work in nonPnP code.

Also check other namespaces, like root\cimv2

–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Thanks Mr. DORON,I even changed device flags to !exclusive,but no way out:( source is as above, it looks fine and no errors but ???
>

You should verify the WMI subsystem compiles and loads the MOF definition.
Even though the MOF compiles during the build, it can still fail loading by
the WMI subsystem at run-time. You ran mofchk during the build, and looked
at the output?

There are some logging levels you can turn on for driver WMI providers;
although on W2K8 I have no idea how to enable them. In W2K3 you set a
registry entry and got pretty useful log files in I believe
\windows\system32\wbem\logs . I assume W2K8R2 has some ETW tracing available
for WMI.

A second thing you can do is take a WMI gui tool like wbemtest, and see if
your class definition can be found. If not, suspect a syntax error in your
mof or something wrong with how the binary MOF is loaded. I’d recommend
starting with a REAL simple MOF, like a copy of one know to work.

If it’s proven the WMI subsystem loads your MOF definition, you might try
using one of the IRP tracing tools (or windbg breaking on the correct IRP
dispatch routine) to verify you get the WMI registration and actions IRP’s .
Doron verified a non-PnP driver should support WMI, and there may be some
subtle little requirements for it to work, like for example I assume PDO
based instance naming will cause it not to work, perhaps by rudely doing
nothing without messages, or perhaps returning some error to some API call.

Note that PowerShell is just super cool for exercising driver WMI code. You
basically have an instant command line interface with data/method support
for your driver’s WMI instances/methods. I’ve used WMI methods to do things
like trigger hardware registers for fault injection during testing, or
during development have a generic WMI method to read/write all my device
registers directly. A little PowerShell script can then dump formatted
debugging data about the state of the driver and hardware. For production,
you turn off anything dangerous or that you don’t to escape your lab (you
can have debug and release MOF definitions).

Jan

While trying to implement WMI in one of my projects, faced a really though
problem (at least for me - a WMI beginner) I have been trying to figure it
out,
for 3 days. So asking was the last resort:<

Thanks to all GURUs (Mr. Mark, Doron, Maxim, Jan) for helping me figure out the problem. This is 5th day, and finally problem is solved.

Everything was ok, except 1 line of command :

mofcomp -N:root\wmi Wmi42.mof

This registers the MOF and updates the repository. SO IT WORKS NOW:):slight_smile: Currently, it seems that , after running the client app, i will pipe to cmd.exe for running this line of code. But it seems nonsense, isn’t it? Coz, I embedded the compiled MOF into driver, WHY re-compiling with mofcomp to REGISTER???

Anyway, i will try to make this work, one way or another…

++Any ideas, without piping to cmd will be useful.++

Sincerely,
EMRE (Happy guy:)

> This registers the MOF and updates the repository. SO IT WORKS NOW:):slight_smile: Currently, it seems that ,

after running the client app, i will pipe to cmd.exe for running this line of code. But it seems nonsense,
isn’t it? Coz, I embedded the compiled MOF into driver, WHY re-compiling with mofcomp to
REGISTER???

Surely WMI must work without this.

I think you can have a bug in the WMI registration paths in your driver.

–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

In the book, it says that this is required for OLD SYSTEMS, excerpt is below :

"MOF Files and Beta Releases
WMI was under active development during much of the Windows 2000 beta-testing period, and not all of the plumbing was complete. Depending on which release of Windows 2000 you’re using, you might need to run the MOF compiler an extra time before you’ll be able to run the sample programs described in this chapter. During the extra run, you’ll manually update the WMI repository so that various COM interfaces can access your driver’s schema. Use the following command-line syntax to place your schema into the WMI namespace:

mofcomp -N:root\wmi "

I verified, driver DISPATCH FUNCTIONS are not called when i try to read class properties…
I think i will lose my mind:(
???