Hi,
i am pretty stuck on a problem: I do have the PDO Name for a Device on my System, lets say it is “\Device\000000aa” that maps to my Modem. I would like to drop a Zw/NtGetDevicePowerState(…) in Usermode on the Device,…but “how” do i get a handle to the Device so i can pass that to the Zw/NtGetDevicePowerState? What NtOpen*/NtCreate* do i have to use here and how do i have to pass the PDO Name to that? This should also work on Windows 2000. In Windows XP+ you have SetupDiGetDeviceRegistryProperty(…) and SPDRP_DEVICE_POWER_DATA that maps to a CM_POWER_DATA, but only XP+! I also have the Device Hardware/Compatible/Instance ID’s so i may can use them to get a handle for the Device?
Thanks in advance,…
Regards
K.
2 things are working against you
- the power state reported is only valid if the bus driver calls PoSetPowerState on the PDO at the right time. Chances are, esp on win2k, the bus driver is not doing it
- to get a handle from user mode you either
a) pass the name to NtCreateFile, but that is not a documented function
b) create a symbolic link to the NT name via DefineDosDevice and then pass that symbolic link name to CreateFile
…BUT there is no guarantee that you can successfully open the handle. The FDO on top of the PDO, particularly in the modem case, may enforce exclusive handle semantics and if some other app has the modem already opened, your create will be denied.
Why does the power state matter? Why do you need it?
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@arcor.de
Sent: Thursday, December 10, 2009 9:59 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Device Power State from PDO Name in Usermode
Hi,
i am pretty stuck on a problem: I do have the PDO Name for a Device on my System, lets say it is “\Device\000000aa” that maps to my Modem. I would like to drop a Zw/NtGetDevicePowerState(…) in Usermode on the Device,…but “how” do i get a handle to the Device so i can pass that to the Zw/NtGetDevicePowerState? What NtOpen*/NtCreate* do i have to use here and how do i have to pass the PDO Name to that? This should also work on Windows 2000. In Windows XP+ you have SetupDiGetDeviceRegistryProperty(…) and SPDRP_DEVICE_POWER_DATA that maps to a CM_POWER_DATA, but only XP+! I also have the Device Hardware/Compatible/Instance ID’s so i may can use them to get a handle for the Device?
Thanks in advance,…
Regards
K.
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
Hi Doron,
thanks for the answer. Well, i was looking for some functions regarding the system power state and then i found the GetDevicePowerState(…) and i was just wondering on what current power state all the Devices on my System are running at this moment. I wanted to see what all the devices are looking like on my several Virtual PC Images, ranging from Windows 2000 to 7. I know Device Manager could show me that, but i wanted to do it with that function. You say that W2K especially is not accurate on that device power state reporting, why? You also say that i can create a sym-link, but i want to do that, on the other hand i could use Zw/NtCreateFile and this would (possibly) work if there is no enforcement of e.g. exclusive access to the device. Could you please tell me what the OBJECT_ATTRIBUTES should look like for that? The NtCreateFile is well documented, see here:
[NtCreateFile Function]
http://msdn.microsoft.com/en-us/library/bb432380(VS.85).aspx
Regards
K.
Sorry, that is as far as I go. I suggest on xp and later you just use the setup property. Win2k is nearly dead anyways. As for NtCreateFile being well documented, yes and no. at the top you have
Note Before using this function, please read Calling Internal API (http://msdn.microsoft.com/en-us/library/bb432200(VS.85).aspx)
Which clearly states the rules
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@arcor.de
Sent: Thursday, December 10, 2009 10:46 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Device Power State from PDO Name in Usermode
Hi Doron,
thanks for the answer. Well, i was looking for some functions regarding the system power state and then i found the GetDevicePowerState(…) and i was just wondering on what current power state all the Devices on my System are running at this moment. I wanted to see what all the devices are looking like on my several Virtual PC Images, ranging from Windows 2000 to 7. I know Device Manager could show me that, but i wanted to do it with that function. You say that W2K especially is not accurate on that device power state reporting, why? You also say that i can create a sym-link, but i want to do that, on the other hand i could use Zw/NtCreateFile and this would (possibly) work if there is no enforcement of e.g. exclusive access to the device. Could you please tell me what the OBJECT_ATTRIBUTES should look like for that? The NtCreateFile is well documented, see here:
[NtCreateFile Function]
http://msdn.microsoft.com/en-us/library/bb432380(VS.85).aspx
Regards
K.
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
Doron.
I suggest on xp and later you just use the setup property.
Win2k is nearly dead anyways.
Yes it is, but some still run software on that, i do check some of my applicatiosn i write on that
because we still have Windows 2000 Clients and even Servers running. Servers are not that important to me, but the Clients still run and will run. So i have VPC with W2K for testing purposes,…
As for NtCreateFile being well documented, yes and no. at the top you have Note Before using
this function, please read Calling Internal API (http://msdn.microsoft.com/en-us/library
/bb432200(VS.85).aspx) Which clearly states the rules
I am aware of that,…i always was.
Which clearly states the rules
Yes it does,…
But thanks for the NtCreateFile hint, it works! But i am not sure what i have to use on the “CreateOptions” parameter for the NtCreateFile.
Regards
K.