Hello,

I'm trying to register my driver to recieve shut down notification when the
user
shuts the system down. I found this API for my WDF driver

WdfControlDeviceInitSetShutdownNotification

The question I have is do i need to create a new Device_Init structure using
WdfControlDeviceInitAllocate. or can i just use the DeviceInit pass to me
from DeviceAdd ?

Thanks
Mel

Re: WdfControlDeviceInitSetShutdownNotification by Eliyas

Eliyas
Sun Oct 07 07:13:41 PDT 2007

You cannot use the DeviceInit passed to the AddDevice. This function is
meant for non plug-n-play devices. If you are writing a legacy (NT4.0)
driver then you allocate a control-deviceinit structure and use that to
register shutdown notification. For pnp-device, you don't need to use this
function. You can use EvtDeviceD0Exit - device power state
WdfPowerDeviceD3Final - to get the notification.

-Eliyas

"hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
news:D6667A0D-37C8-47F4-B235-C38678047EE8@microsoft.com...
> Hello,
>
> I'm trying to register my driver to recieve shut down notification when
> the
> user
> shuts the system down. I found this API for my WDF driver
>
> WdfControlDeviceInitSetShutdownNotification
>
> The question I have is do i need to create a new Device_Init structure
> using
> WdfControlDeviceInitAllocate. or can i just use the DeviceInit pass to me
> from DeviceAdd ?
>
> Thanks
> Mel
>

Re: WdfControlDeviceInitSetShutdownNotification by hammerli22

hammerli22
Tue Oct 09 09:24:01 PDT 2007

Hi Eliyas,

I tried using EvtDeviceD0Exit but my driver gets called when it is unloaded,
like when I am updating the driver. Is there no other to way get called back
only when
the operating system is shuting down only or is there a way to tell if the
system
is going down while i am running in EvtDeviceD0Exit so that I can ttell the
difference between the os really going down versus just being just unloaded.

thanks
Mel


"Eliyas Yakub [MSFT]" wrote:

> You cannot use the DeviceInit passed to the AddDevice. This function is
> meant for non plug-n-play devices. If you are writing a legacy (NT4.0)
> driver then you allocate a control-deviceinit structure and use that to
> register shutdown notification. For pnp-device, you don't need to use this
> function. You can use EvtDeviceD0Exit - device power state
> WdfPowerDeviceD3Final - to get the notification.
>
> -Eliyas
>
> "hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
> news:D6667A0D-37C8-47F4-B235-C38678047EE8@microsoft.com...
> > Hello,
> >
> > I'm trying to register my driver to recieve shut down notification when
> > the
> > user
> > shuts the system down. I found this API for my WDF driver
> >
> > WdfControlDeviceInitSetShutdownNotification
> >
> > The question I have is do i need to create a new Device_Init structure
> > using
> > WdfControlDeviceInitAllocate. or can i just use the DeviceInit pass to me
> > from DeviceAdd ?
> >
> > Thanks
> > Mel
> >

Re: WdfControlDeviceInitSetShutdownNotification by Eliyas

Eliyas
Tue Oct 09 11:52:24 PDT 2007

Why do you want to know whether the system is being shutdown? This is not a
rude question. Just want to understand the technical details.

Unfortunately we don't have an interface in 1.5 version of framework to get
that information. We have added a new function in the next version of
framework (1.7 to be release as part of Windows Server 2008) called
WdfDeviceGetSystemPowerAction that will enable you to differentiate.

The workaround would be to register WDM preprocess callback for
IRP_MJ_POWER/IRP_MN_SET_POWER and look for Sx IRP.

-Eliyas


Re: WdfControlDeviceInitSetShutdownNotification by Doron

Doron
Tue Oct 09 11:53:47 PDT 2007

why is shutdown a special case? why wouuldn't you just do it on device
unload as well?

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
news:C046FCBA-5F18-4567-8D1A-E5A0112CC559@microsoft.com...
> Hi Eliyas,
>
> I tried using EvtDeviceD0Exit but my driver gets called when it is
> unloaded,
> like when I am updating the driver. Is there no other to way get called
> back
> only when
> the operating system is shuting down only or is there a way to tell if the
> system
> is going down while i am running in EvtDeviceD0Exit so that I can ttell
> the
> difference between the os really going down versus just being just
> unloaded.
>
> thanks
> Mel
>
>
> "Eliyas Yakub [MSFT]" wrote:
>
>> You cannot use the DeviceInit passed to the AddDevice. This function is
>> meant for non plug-n-play devices. If you are writing a legacy (NT4.0)
>> driver then you allocate a control-deviceinit structure and use that to
>> register shutdown notification. For pnp-device, you don't need to use
>> this
>> function. You can use EvtDeviceD0Exit - device power state
>> WdfPowerDeviceD3Final - to get the notification.
>>
>> -Eliyas
>>
>> "hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
>> news:D6667A0D-37C8-47F4-B235-C38678047EE8@microsoft.com...
>> > Hello,
>> >
>> > I'm trying to register my driver to recieve shut down notification when
>> > the
>> > user
>> > shuts the system down. I found this API for my WDF driver
>> >
>> > WdfControlDeviceInitSetShutdownNotification
>> >
>> > The question I have is do i need to create a new Device_Init structure
>> > using
>> > WdfControlDeviceInitAllocate. or can i just use the DeviceInit pass to
>> > me
>> > from DeviceAdd ?
>> >
>> > Thanks
>> > Mel
>> >


Re: WdfControlDeviceInitSetShutdownNotification by hammerli22

hammerli22
Tue Oct 09 18:39:00 PDT 2007

When the system is going down the driver is suppose to check a registry
location at
a parent location of
\\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Reliability\....
for 2 values and then write their values if they exist to a hardware log
before the system completely shuts down.

So the 1st problem is when going down i don't seem to able to get to the
SOFTWARE hive as it appears to be unmounted at EvtDeviceD0Exit time.
I can get to it when unloading the driver when the o/s is still up but not
when the o/s is shutting down.

The driver shouldn't log to the hardware if its being unloaded because the
o/s is really not shutting down, the driver is just going away thats why
I can't just use EvtDeviceD0Exit .


Thanks
Mel

P.S. The specification for the driver come from a msft document i can email it
it if you like.



"Doron Holan [MSFT]" wrote:

> why is shutdown a special case? why wouuldn't you just do it on device
> unload as well?
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
> news:C046FCBA-5F18-4567-8D1A-E5A0112CC559@microsoft.com...
> > Hi Eliyas,
> >
> > I tried using EvtDeviceD0Exit but my driver gets called when it is
> > unloaded,
> > like when I am updating the driver. Is there no other to way get called
> > back
> > only when
> > the operating system is shuting down only or is there a way to tell if the
> > system
> > is going down while i am running in EvtDeviceD0Exit so that I can ttell
> > the
> > difference between the os really going down versus just being just
> > unloaded.
> >
> > thanks
> > Mel
> >
> >
> > "Eliyas Yakub [MSFT]" wrote:
> >
> >> You cannot use the DeviceInit passed to the AddDevice. This function is
> >> meant for non plug-n-play devices. If you are writing a legacy (NT4.0)
> >> driver then you allocate a control-deviceinit structure and use that to
> >> register shutdown notification. For pnp-device, you don't need to use
> >> this
> >> function. You can use EvtDeviceD0Exit - device power state
> >> WdfPowerDeviceD3Final - to get the notification.
> >>
> >> -Eliyas
> >>
> >> "hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
> >> news:D6667A0D-37C8-47F4-B235-C38678047EE8@microsoft.com...
> >> > Hello,
> >> >
> >> > I'm trying to register my driver to recieve shut down notification when
> >> > the
> >> > user
> >> > shuts the system down. I found this API for my WDF driver
> >> >
> >> > WdfControlDeviceInitSetShutdownNotification
> >> >
> >> > The question I have is do i need to create a new Device_Init structure
> >> > using
> >> > WdfControlDeviceInitAllocate. or can i just use the DeviceInit pass to
> >> > me
> >> > from DeviceAdd ?
> >> >
> >> > Thanks
> >> > Mel
> >> >
>
>

Re: WdfControlDeviceInitSetShutdownNotification by Doron

Doron
Wed Oct 10 08:59:00 PDT 2007

look at the Ex callback objects
(http://msdn2.microsoft.com/en-us/library/aa489845.aspx), specifically
\Callback\PowerState which will be called right before the OS moves into Sx
and the hives should still be there. Technically speaking a driver should
not be touching HKLM\Software. A better design here would be to have a user
mode service which reads the keys on system shutdown and writes to a log.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
news:E1923EA3-EDD3-4B6F-8EA5-F869F0B3A9C8@microsoft.com...
> When the system is going down the driver is suppose to check a registry
> location at
> a parent location of
> \\REGISTRY\\MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Reliability\....
> for 2 values and then write their values if they exist to a hardware log
> before the system completely shuts down.
>
> So the 1st problem is when going down i don't seem to able to get to the
> SOFTWARE hive as it appears to be unmounted at EvtDeviceD0Exit time.
> I can get to it when unloading the driver when the o/s is still up but not
> when the o/s is shutting down.
>
> The driver shouldn't log to the hardware if its being unloaded because the
> o/s is really not shutting down, the driver is just going away thats why
> I can't just use EvtDeviceD0Exit .
>
>
> Thanks
> Mel
>
> P.S. The specification for the driver come from a msft document i can
> email it
> it if you like.
>
>
>
> "Doron Holan [MSFT]" wrote:
>
>> why is shutdown a special case? why wouuldn't you just do it on device
>> unload as well?
>>
>> --
>> Please do not send e-mail directly to this alias. this alias is for
>> newsgroup purposes only.
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>> "hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
>> news:C046FCBA-5F18-4567-8D1A-E5A0112CC559@microsoft.com...
>> > Hi Eliyas,
>> >
>> > I tried using EvtDeviceD0Exit but my driver gets called when it is
>> > unloaded,
>> > like when I am updating the driver. Is there no other to way get called
>> > back
>> > only when
>> > the operating system is shuting down only or is there a way to tell if
>> > the
>> > system
>> > is going down while i am running in EvtDeviceD0Exit so that I can ttell
>> > the
>> > difference between the os really going down versus just being just
>> > unloaded.
>> >
>> > thanks
>> > Mel
>> >
>> >
>> > "Eliyas Yakub [MSFT]" wrote:
>> >
>> >> You cannot use the DeviceInit passed to the AddDevice. This function
>> >> is
>> >> meant for non plug-n-play devices. If you are writing a legacy (NT4.0)
>> >> driver then you allocate a control-deviceinit structure and use that
>> >> to
>> >> register shutdown notification. For pnp-device, you don't need to use
>> >> this
>> >> function. You can use EvtDeviceD0Exit - device power state
>> >> WdfPowerDeviceD3Final - to get the notification.
>> >>
>> >> -Eliyas
>> >>
>> >> "hammerli22" <hammerli22@discussions.microsoft.com> wrote in message
>> >> news:D6667A0D-37C8-47F4-B235-C38678047EE8@microsoft.com...
>> >> > Hello,
>> >> >
>> >> > I'm trying to register my driver to recieve shut down notification
>> >> > when
>> >> > the
>> >> > user
>> >> > shuts the system down. I found this API for my WDF driver
>> >> >
>> >> > WdfControlDeviceInitSetShutdownNotification
>> >> >
>> >> > The question I have is do i need to create a new Device_Init
>> >> > structure
>> >> > using
>> >> > WdfControlDeviceInitAllocate. or can i just use the DeviceInit pass
>> >> > to
>> >> > me
>> >> > from DeviceAdd ?
>> >> >
>> >> > Thanks
>> >> > Mel
>> >> >
>>
>>