After a service/driver (.sys) is started, normally communication happens through a file (client pseudo code):
HANDLE gHandle = CreateFileA("\\.\DriverFile",
GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
...
DeviceIoControl(gHandle, MY_MSG_ID, NULL, 0, &refCount,
sizeof(refCount), &length, NULL);
...
CloseHandle(gHandle);
Is there a way to know how many clients have open connection to the driver file?
One way to impl it, is to handle IRP_MJ_CREATE/IRP_MJ_CLOSE on the driver side and keep ref count manually; then using some message to the driver client code could retrieve the count. Is there a way to do that without involving changes to the driver side?