question about starting/stopping a service...

I wrote (found code on the internet :wink: ) a usermode tool that loads and
unloads my driver, but it has a strange habit that it really starting to
bug me.

The first time I load my driver everything works fine. I then unload my
driver (call ControlService(SERVICE_CONTROL_STOP) followed by a call to
DeleteService(), both of which succeed) and exit my app. At the
commandline, though, if I type “sc query mydrivername” it shows that my
driver is in the “stopped” state. Now when I restart my app and try to
load my service again, StartService returns ERROR_SERVICE_DISABLED. The
next time I restart my app, though, all if good. If I restart again,
though, then the process repeats itself- in between each successful run
I have an unsuccessful one. I’ve tried adding code to “re-shutdown” my
driver when I can’t load it, but that has no effect.

Two questions: 1) Can anyone explain why this happens? It doesn’t seem
to be a time thing- I can wait several minutes between runs and still
have the problem (although if I more than several minutes I have seen
the problem fix itself). 2) How can I avoid it? Is there some way to
restart a disabled driver (I tried sending
ControlService(SERVICE_CONTROL_CONTINUE) but that doesn’t work).

Thanks,
–Jeremy

After the call to ControlService, are you waiting for the service to stop?
You can call QueryServiceStatus in a loop and wait until dwCurrentState <>
SERVICE_STOP_PENDING, and then you can call DeleteService.

Is this a PnP driver?

Gary G. Little

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Tuesday, September 12, 2006 8:31 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] question about starting/stopping a service…

I wrote (found code on the internet :wink: ) a usermode tool that loads and
unloads my driver, but it has a strange habit that it really starting to bug
me.

The first time I load my driver everything works fine. I then unload my
driver (call ControlService(SERVICE_CONTROL_STOP) followed by a call to
DeleteService(), both of which succeed) and exit my app. At the commandline,
though, if I type “sc query mydrivername” it shows that my driver is in the
“stopped” state. Now when I restart my app and try to load my service again,
StartService returns ERROR_SERVICE_DISABLED. The next time I restart my app,
though, all if good. If I restart again, though, then the process repeats
itself- in between each successful run I have an unsuccessful one. I’ve
tried adding code to “re-shutdown” my driver when I can’t load it, but that
has no effect.

Two questions: 1) Can anyone explain why this happens? It doesn’t seem to be
a time thing- I can wait several minutes between runs and still have the
problem (although if I more than several minutes I have seen the problem fix
itself). 2) How can I avoid it? Is there some way to restart a disabled
driver (I tried sending
ControlService(SERVICE_CONTROL_CONTINUE) but that doesn’t work).

Thanks,
–Jeremy


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

I inserted a wait loop (5 times, 1 second apart) and the current state
is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based on
the nonpnp KMDF sample.

–Jeremy

King Brian wrote:

After the call to ControlService, are you waiting for the service to
stop? You can call QueryServiceStatus in a loop and wait until
dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
DeleteService.

Try the same experiment from the command line (net start yourdriver; net
stop yourdriver; repeat as needed.) If this is also not working then the
problem is in your driver. If it works then the problem is in your
service control api code. Your driver does have an unload routine right?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 1:16 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I inserted a wait loop (5 times, 1 second apart) and the current state
is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based on
the nonpnp KMDF sample.

–Jeremy

King Brian wrote:

After the call to ControlService, are you waiting for the service to
stop? You can call QueryServiceStatus in a loop and wait until
dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
DeleteService.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

It certainly sounds like you have a handle open somewhere, or a
reference that wasn’t released.

If it’s still a KMDF Driver, have you tried using the Wdf verifier and a
trace? It can help point to something left out [you can count opens and
closes].

You can also use the KD Extension !wdfdriverinfo to dump all the objects
remaining in your driver, and see if it’s what you expect it to be.

You can also just break into the debugger and check the reference counts
on your device object and driver object (assuming you know the Devobj
address). But they won’t tell you why they are what they are.

Also, if this happens to be the driver that’s emulating a storage
device, do you have a command prompt open with the current directory
pointing at the virtual device? That leaves a file open on the device,
IIRC.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 10:16 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I inserted a wait loop (5 times, 1 second apart) and the current state
is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based on
the nonpnp KMDF sample.

–Jeremy

King Brian wrote:

After the call to ControlService, are you waiting for the service to
stop? You can call QueryServiceStatus in a loop and wait until
dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
DeleteService.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

When I try ‘net start’ I get an error saying that the service name is
not valid. I assume the name is supposed to be the filename of my driver
without the .sys?

Anyway, I did another test where I load the service, load my controller
device, but do not mount any disk images, and then shutdown, and
everything exits cleanly. I’ll go sniffing around in the mounting code
and see if I’m leaking any resources. The strange thing is that even
when I shutdown the service after a mount, eventually (after 5-10
minutes) the OS (?) cleans something up and the service fully shuts down.
–Jeremy

Roddy, Mark wrote:

Try the same experiment from the command line (net start yourdriver; net
stop yourdriver; repeat as needed.) If this is also not working then the
problem is in your driver. If it works then the problem is in your
service control api code. Your driver does have an unload routine right?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 1:16 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I inserted a wait loop (5 times, 1 second apart) and the current state
is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based on
the nonpnp KMDF sample.

–Jeremy

King Brian wrote:
> After the call to ControlService, are you waiting for the service to
> stop? You can call QueryServiceStatus in a loop and wait until
> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
> DeleteService.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Jeremy Chaney[SMTP:xxxxx@telestream.net]
Reply To: Windows System Software Devs Interest List
Sent: Wednesday, September 13, 2006 7:45 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

When I try ‘net start’ I get an error saying that the service name is
not valid. I assume the name is supposed to be the filename of my driver
without the .sys?

No. IIRC it can be display name or the key name in the registry under CCS\Services. You can also use sc.exe to display config and control driver/service. It is trivial task, just read help and experiment.

Anyway, I did another test where I load the service, load my controller
device, but do not mount any disk images, and then shutdown, and
everything exits cleanly. I’ll go sniffing around in the mounting code
and see if I’m leaking any resources. The strange thing is that even
when I shutdown the service after a mount, eventually (after 5-10
minutes) the OS (?) cleans something up and the service fully shuts down.

What do you have – virtual disk driver? In this case you have to dismount all drives before unloading. There are references from mounted FS, apps which can have opened directories etc.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

When I try ‘net start’ I get an error saying that the service name is
not valid. I assume the name is supposed to be the filename of my driver

without the .sys?

I believe this is happening because you are deleting the service
(according to your earlier posts). Once your app finishes, the service
no longer “exists” for the Service manager to start.

The name you use is the name you gave the service in CreateService- by
convention it is usually the driver base file name, but it doesn’t have
to be.

Anyway, I did another test where I load the service, load my controller
device, but do not mount any disk images, and then shutdown, and
everything exits cleanly. I’ll go sniffing around in the mounting code
and see if I’m leaking any resources. The strange thing is that even
when I shutdown the service after a mount, eventually (after 5-10
minutes) the OS (?) cleans something up and the service fully shuts
down.

I’m working an a similar driver (except root-enumerated). When I report
a storage interface, I get a storage class driver stack loaded above me,
and it has a file object open on me.

But since I’m Pnp, I’m not having any problems with removal.

Ah sorry this is a disk device with volumes - so there are very likely
cached references to, at a minimum, the root directory of the volume.
The stop is not going to complete until those references go away.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 1:45 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

When I try ‘net start’ I get an error saying that the service name is
not valid. I assume the name is supposed to be the filename of my driver

without the .sys?

Anyway, I did another test where I load the service, load my controller
device, but do not mount any disk images, and then shutdown, and
everything exits cleanly. I’ll go sniffing around in the mounting code
and see if I’m leaking any resources. The strange thing is that even
when I shutdown the service after a mount, eventually (after 5-10
minutes) the OS (?) cleans something up and the service fully shuts
down.
–Jeremy

Roddy, Mark wrote:

Try the same experiment from the command line (net start yourdriver;
net
stop yourdriver; repeat as needed.) If this is also not working then
the
problem is in your driver. If it works then the problem is in your
service control api code. Your driver does have an unload routine
right?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 1:16 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I inserted a wait loop (5 times, 1 second apart) and the current state

is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based
on
the nonpnp KMDF sample.

–Jeremy

King Brian wrote:
> After the call to ControlService, are you waiting for the service to
> stop? You can call QueryServiceStatus in a loop and wait until
> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
> DeleteService.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Is there any way to ‘un-stop’ the service once it goes into the
“stopping” state? I found a handle leak that I’m fixing so the point may
be moot, but I’m interested to know anyway.

–Jeremy

Roddy, Mark wrote:

Ah sorry this is a disk device with volumes - so there are very likely
cached references to, at a minimum, the root directory of the volume.
The stop is not going to complete until those references go away.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 1:45 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

When I try ‘net start’ I get an error saying that the service name is
not valid. I assume the name is supposed to be the filename of my driver

without the .sys?

Anyway, I did another test where I load the service, load my controller
device, but do not mount any disk images, and then shutdown, and
everything exits cleanly. I’ll go sniffing around in the mounting code
and see if I’m leaking any resources. The strange thing is that even
when I shutdown the service after a mount, eventually (after 5-10
minutes) the OS (?) cleans something up and the service fully shuts
down.
–Jeremy

Roddy, Mark wrote:
> Try the same experiment from the command line (net start yourdriver;
net
> stop yourdriver; repeat as needed.) If this is also not working then
the
> problem is in your driver. If it works then the problem is in your
> service control api code. Your driver does have an unload routine
right?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
> Sent: Wednesday, September 13, 2006 1:16 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] question about starting/stopping a service…
>
> I inserted a wait loop (5 times, 1 second apart) and the current state

> is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
> file handles are closed, and everything is properly cleaned up. What
> kinds of things will prevent a service from shutting down?
>
> In response to Gary’s question, this is a software-only driver based
on
> the nonpnp KMDF sample.
>
> --Jeremy
>
>
> King Brian wrote:
>> After the call to ControlService, are you waiting for the service to
>> stop? You can call QueryServiceStatus in a loop and wait until
>> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
>> DeleteService.
>>
>>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Not that I know of.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 2:33 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

Is there any way to ‘un-stop’ the service once it goes into the
“stopping” state? I found a handle leak that I’m fixing so the point may

be moot, but I’m interested to know anyway.

–Jeremy

Roddy, Mark wrote:

Ah sorry this is a disk device with volumes - so there are very likely
cached references to, at a minimum, the root directory of the volume.
The stop is not going to complete until those references go away.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 1:45 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

When I try ‘net start’ I get an error saying that the service name is
not valid. I assume the name is supposed to be the filename of my
driver

without the .sys?

Anyway, I did another test where I load the service, load my
controller
device, but do not mount any disk images, and then shutdown, and
everything exits cleanly. I’ll go sniffing around in the mounting code

and see if I’m leaking any resources. The strange thing is that even
when I shutdown the service after a mount, eventually (after 5-10
minutes) the OS (?) cleans something up and the service fully shuts
down.
–Jeremy

Roddy, Mark wrote:
> Try the same experiment from the command line (net start yourdriver;
net
> stop yourdriver; repeat as needed.) If this is also not working then
the
> problem is in your driver. If it works then the problem is in your
> service control api code. Your driver does have an unload routine
right?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
> Sent: Wednesday, September 13, 2006 1:16 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] question about starting/stopping a service…
>
> I inserted a wait loop (5 times, 1 second apart) and the current
state

> is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
> file handles are closed, and everything is properly cleaned up. What
> kinds of things will prevent a service from shutting down?
>
> In response to Gary’s question, this is a software-only driver based
on
> the nonpnp KMDF sample.
>
> --Jeremy
>
>
> King Brian wrote:
>> After the call to ControlService, are you waiting for the service to

>> stop? You can call QueryServiceStatus in a loop and wait until
>> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
>> DeleteService.
>>
>>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

I tried using the “!wdfkd.wdfdriverinfo” command, but I get an error
saying that KD could not find my driver in the wdfldr client list.
Running “!wdfkd.wdfldr” returns “error: Could not retrieve
wdfldr!WdfLdrGlobals”. I have the latest symbols installed, and they are
in my search path. Did I miss a step somewhere?
Thanks,
–Jeremy

Bob Kjelgaard wrote:

It certainly sounds like you have a handle open somewhere, or a
reference that wasn’t released.

If it’s still a KMDF Driver, have you tried using the Wdf verifier and a
trace? It can help point to something left out [you can count opens and
closes].

You can also use the KD Extension !wdfdriverinfo to dump all the objects
remaining in your driver, and see if it’s what you expect it to be.

You can also just break into the debugger and check the reference counts
on your device object and driver object (assuming you know the Devobj
address). But they won’t tell you why they are what they are.

Also, if this happens to be the driver that’s emulating a storage
device, do you have a command prompt open with the current directory
pointing at the virtual device? That leaves a file open on the device,
IIRC.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 10:16 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I inserted a wait loop (5 times, 1 second apart) and the current state
is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based on
the nonpnp KMDF sample.

–Jeremy

King Brian wrote:
> After the call to ControlService, are you waiting for the service to
> stop? You can call QueryServiceStatus in a loop and wait until
> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
> DeleteService.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

which build of Vista are you running?

– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 4:47 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I tried using the “!wdfkd.wdfdriverinfo” command, but I get an error
saying that KD could not find my driver in the wdfldr client list.
Running “!wdfkd.wdfldr” returns “error: Could not retrieve
wdfldr!WdfLdrGlobals”. I have the latest symbols installed, and they are
in my search path. Did I miss a step somewhere?
Thanks,
–Jeremy

Bob Kjelgaard wrote:

It certainly sounds like you have a handle open somewhere, or a
reference that wasn’t released.

If it’s still a KMDF Driver, have you tried using the Wdf verifier and

a trace? It can help point to something left out [you can count opens

and closes].

You can also use the KD Extension !wdfdriverinfo to dump all the
objects remaining in your driver, and see if it’s what you expect it
to be.

You can also just break into the debugger and check the reference
counts on your device object and driver object (assuming you know the
Devobj address). But they won’t tell you why they are what they are.

Also, if this happens to be the driver that’s emulating a storage
device, do you have a command prompt open with the current directory
pointing at the virtual device? That leaves a file open on the
device, IIRC.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 10:16 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I inserted a wait loop (5 times, 1 second apart) and the current state

is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
file handles are closed, and everything is properly cleaned up. What
kinds of things will prevent a service from shutting down?

In response to Gary’s question, this is a software-only driver based
on the nonpnp KMDF sample.

–Jeremy

King Brian wrote:
> After the call to ControlService, are you waiting for the service to
> stop? You can call QueryServiceStatus in a loop and wait until
> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
> DeleteService.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

I’m running WindowsXP.
–Jeremy

Doron Holan wrote:

which build of Vista are you running?

– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 4:47 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I tried using the “!wdfkd.wdfdriverinfo” command, but I get an error
saying that KD could not find my driver in the wdfldr client list.
Running “!wdfkd.wdfldr” returns “error: Could not retrieve
wdfldr!WdfLdrGlobals”. I have the latest symbols installed, and they are
in my search path. Did I miss a step somewhere?
Thanks,
–Jeremy

Bob Kjelgaard wrote:
> It certainly sounds like you have a handle open somewhere, or a
> reference that wasn’t released.
>
> If it’s still a KMDF Driver, have you tried using the Wdf verifier and

> a trace? It can help point to something left out [you can count opens

> and closes].
>
> You can also use the KD Extension !wdfdriverinfo to dump all the
> objects remaining in your driver, and see if it’s what you expect it
to be.
> You can also just break into the debugger and check the reference
> counts on your device object and driver object (assuming you know the
> Devobj address). But they won’t tell you why they are what they are.
>
> Also, if this happens to be the driver that’s emulating a storage
> device, do you have a command prompt open with the current directory
> pointing at the virtual device? That leaves a file open on the
> device, IIRC.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
> Sent: Wednesday, September 13, 2006 10:16 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] question about starting/stopping a service…
>
> I inserted a wait loop (5 times, 1 second apart) and the current state

> is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
> file handles are closed, and everything is properly cleaned up. What
> kinds of things will prevent a service from shutting down?
>
> In response to Gary’s question, this is a software-only driver based
> on the nonpnp KMDF sample.
>
> --Jeremy
>
>
> King Brian wrote:
>> After the call to ControlService, are you waiting for the service to
>> stop? You can call QueryServiceStatus in a loop and wait until
>> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
>> DeleteService.
>>
>>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Is this on XP? A while back I had to write some code for XP to delete a
non-PnP driver using the DeleteService API. I observed similar behavior as
you, where my service was not deleted even after the DeleteService function
call returned. My understanding is that DeleteService happens asynchronously
(on XP at least). I had to work around this by polling the service in loop
after the DeleteService call until the service got deleted.

// Delete the service
DeleteService();

// Wait for the service to get deleted
for (i=0; i < FewTimes; i++)
{
serviceHandle = OpenService();
if (NULL != serviceHandle)
{
// service not deleted yet

// The QueryService below was needed, but I can’t remember why :frowning:
QueryService();

CloseHandle(serviceHandle);
}
else
{
// service deleted!
break;
}
}

Thanks,
Abhishek

“Jeremy Chaney” wrote in message
news:xxxxx@ntdev…
>I wrote (found code on the internet :wink: ) a usermode tool that loads and
>unloads my driver, but it has a strange habit that it really starting to
>bug me.
>
> The first time I load my driver everything works fine. I then unload my
> driver (call ControlService(SERVICE_CONTROL_STOP) followed by a call to
> DeleteService(), both of which succeed) and exit my app. At the
> commandline, though, if I type “sc query mydrivername” it shows that my
> driver is in the “stopped” state. Now when I restart my app and try to
> load my service again, StartService returns ERROR_SERVICE_DISABLED. The
> next time I restart my app, though, all if good. If I restart again,
> though, then the process repeats itself- in between each successful run I
> have an unsuccessful one. I’ve tried adding code to “re-shutdown” my
> driver when I can’t load it, but that has no effect.
>
> Two questions: 1) Can anyone explain why this happens? It doesn’t seem to
> be a time thing- I can wait several minutes between runs and still have
> the problem (although if I more than several minutes I have seen the
> problem fix itself). 2) How can I avoid it? Is there some way to restart a
> disabled driver (I tried sending ControlService(SERVICE_CONTROL_CONTINUE)
> but that doesn’t work).
>
> Thanks,
> --Jeremy
>

What version of KMDF? V1.5 from the WDK? If so, can you try the RC1
WDK bits? Otherwise, the v1.5 symbols are not on the symbol server.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 5:40 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I’m running WindowsXP.
–Jeremy

Doron Holan wrote:

which build of Vista are you running?

– I can spell, I just can’t type.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 4:47 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I tried using the “!wdfkd.wdfdriverinfo” command, but I get an error
saying that KD could not find my driver in the wdfldr client list.
Running “!wdfkd.wdfldr” returns “error: Could not retrieve
wdfldr!WdfLdrGlobals”. I have the latest symbols installed, and they
are
in my search path. Did I miss a step somewhere?
Thanks,
–Jeremy

Bob Kjelgaard wrote:
> It certainly sounds like you have a handle open somewhere, or a
> reference that wasn’t released.
>
> If it’s still a KMDF Driver, have you tried using the Wdf verifier
and

> a trace? It can help point to something left out [you can count
opens

> and closes].
>
> You can also use the KD Extension !wdfdriverinfo to dump all the
> objects remaining in your driver, and see if it’s what you expect it
to be.
> You can also just break into the debugger and check the reference
> counts on your device object and driver object (assuming you know the

> Devobj address). But they won’t tell you why they are what they are.
>
> Also, if this happens to be the driver that’s emulating a storage
> device, do you have a command prompt open with the current directory
> pointing at the virtual device? That leaves a file open on the
> device, IIRC.
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
> Sent: Wednesday, September 13, 2006 10:16 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] question about starting/stopping a service…
>
> I inserted a wait loop (5 times, 1 second apart) and the current
state

> is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
> file handles are closed, and everything is properly cleaned up. What
> kinds of things will prevent a service from shutting down?
>
> In response to Gary’s question, this is a software-only driver based
> on the nonpnp KMDF sample.
>
> --Jeremy
>
>
> King Brian wrote:
>> After the call to ControlService, are you waiting for the service to

>> stop? You can call QueryServiceStatus in a loop and wait until
>> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
>> DeleteService.
>>
>>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

I can’t quite tell which version I’m using. The directory is KMDF10, but
the coinstaller version is “1.1.0.0”. I tried to download the WDK
yesterday, but I can’t seem to find a version of it that is not tied to
Vista (vista_5600.16384.060829-2230-LR1WDK_EN.iso). Is this correct? If
I do install the WDK, what affect does it have on my build (it doesn’t
replace any KMDF headers or libraries right)?
–Jeremy

Doron Holan wrote:

What version of KMDF? V1.5 from the WDK? If so, can you try the RC1
WDK bits? Otherwise, the v1.5 symbols are not on the symbol server.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
Sent: Wednesday, September 13, 2006 5:40 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] question about starting/stopping a service…

I’m running WindowsXP.
–Jeremy

Doron Holan wrote:
> which build of Vista are you running?
>
> – I can spell, I just can’t type.
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
> Sent: Wednesday, September 13, 2006 4:47 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] question about starting/stopping a service…
>
> I tried using the “!wdfkd.wdfdriverinfo” command, but I get an error
> saying that KD could not find my driver in the wdfldr client list.
> Running “!wdfkd.wdfldr” returns “error: Could not retrieve
> wdfldr!WdfLdrGlobals”. I have the latest symbols installed, and they
are
> in my search path. Did I miss a step somewhere?
> Thanks,
> --Jeremy
>
>
> Bob Kjelgaard wrote:
>> It certainly sounds like you have a handle open somewhere, or a
>> reference that wasn’t released.
>>
>> If it’s still a KMDF Driver, have you tried using the Wdf verifier
and
>> a trace? It can help point to something left out [you can count
opens
>> and closes].
>>
>> You can also use the KD Extension !wdfdriverinfo to dump all the
>> objects remaining in your driver, and see if it’s what you expect it
> to be.
>> You can also just break into the debugger and check the reference
>> counts on your device object and driver object (assuming you know the

>> Devobj address). But they won’t tell you why they are what they are.
>>
>> Also, if this happens to be the driver that’s emulating a storage
>> device, do you have a command prompt open with the current directory
>> pointing at the virtual device? That leaves a file open on the
>> device, IIRC.
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
>> Sent: Wednesday, September 13, 2006 10:16 AM
>> To: Windows System Software Devs Interest List
>> Subject: Re:[ntdev] question about starting/stopping a service…
>>
>> I inserted a wait loop (5 times, 1 second apart) and the current
state
>> is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
>> file handles are closed, and everything is properly cleaned up. What
>> kinds of things will prevent a service from shutting down?
>>
>> In response to Gary’s question, this is a software-only driver based
>> on the nonpnp KMDF sample.
>>
>> --Jeremy
>>
>>
>> King Brian wrote:
>>> After the call to ControlService, are you waiting for the service to

>>> stop? You can call QueryServiceStatus in a loop and wait until
>>> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
>>> DeleteService.
>>>
>>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

The WDK is the Vista version of the DDK. It supports Vista and everything
back to 2000. You have the correct version.

–
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply

“Jeremy Chaney” wrote in message
news:xxxxx@ntdev…
>I can’t quite tell which version I’m using. The directory is KMDF10, but
>the coinstaller version is “1.1.0.0”. I tried to download the WDK
>yesterday, but I can’t seem to find a version of it that is not tied to
>Vista (vista_5600.16384.060829-2230-LR1WDK_EN.iso). Is this correct? If I
>do install the WDK, what affect does it have on my build (it doesn’t
>replace any KMDF headers or libraries right)?
> --Jeremy
>
>
> Doron Holan wrote:
>> What version of KMDF? V1.5 from the WDK? If so, can you try the RC1
>> WDK bits? Otherwise, the v1.5 symbols are not on the symbol server.
>>
>> d
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
>> Sent: Wednesday, September 13, 2006 5:40 PM
>> To: Windows System Software Devs Interest List
>> Subject: Re:[ntdev] question about starting/stopping a service…
>>
>> I’m running WindowsXP.
>> --Jeremy
>>
>>
>> Doron Holan wrote:
>>> which build of Vista are you running?
>>>
>>> – I can spell, I just can’t type.
>>> -----Original Message-----
>>> From: xxxxx@lists.osr.com
>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
>>> Sent: Wednesday, September 13, 2006 4:47 PM
>>> To: Windows System Software Devs Interest List
>>> Subject: Re:[ntdev] question about starting/stopping a service…
>>>
>>> I tried using the “!wdfkd.wdfdriverinfo” command, but I get an error
>>> saying that KD could not find my driver in the wdfldr client list.
>>> Running “!wdfkd.wdfldr” returns “error: Could not retrieve
>>> wdfldr!WdfLdrGlobals”. I have the latest symbols installed, and they
>> are
>>> in my search path. Did I miss a step somewhere?
>>> Thanks,
>>> --Jeremy
>>>
>>>
>>> Bob Kjelgaard wrote:
>>>> It certainly sounds like you have a handle open somewhere, or a
>>>> reference that wasn’t released.
>>>>
>>>> If it’s still a KMDF Driver, have you tried using the Wdf verifier
>> and
>>>> a trace? It can help point to something left out [you can count
>> opens
>>>> and closes].
>>>>
>>>> You can also use the KD Extension !wdfdriverinfo to dump all the
>>>> objects remaining in your driver, and see if it’s what you expect it
>>> to be.
>>>> You can also just break into the debugger and check the reference
>>>> counts on your device object and driver object (assuming you know the
>>
>>>> Devobj address). But they won’t tell you why they are what they are.
>>>>
>>>> Also, if this happens to be the driver that’s emulating a storage
>>>> device, do you have a command prompt open with the current directory
>>>> pointing at the virtual device? That leaves a file open on the device,
>>>> IIRC.
>>>>
>>>> -----Original Message-----
>>>> From: xxxxx@lists.osr.com
>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Jeremy Chaney
>>>> Sent: Wednesday, September 13, 2006 10:16 AM
>>>> To: Windows System Software Devs Interest List
>>>> Subject: Re:[ntdev] question about starting/stopping a service…
>>>>
>>>> I inserted a wait loop (5 times, 1 second apart) and the current
>> state
>>>> is continuously SERVICE_STOP_PENDING. As far as I can tell all of my
>>>> file handles are closed, and everything is properly cleaned up. What
>>>> kinds of things will prevent a service from shutting down?
>>>>
>>>> In response to Gary’s question, this is a software-only driver based on
>>>> the nonpnp KMDF sample.
>>>>
>>>> --Jeremy
>>>>
>>>>
>>>> King Brian wrote:
>>>>> After the call to ControlService, are you waiting for the service to
>>
>>>>> stop? You can call QueryServiceStatus in a loop and wait until
>>>>> dwCurrentState <> SERVICE_STOP_PENDING, and then you can call
>>>>> DeleteService.
>>>>>
>>>>>
>>>> —
>>>> Questions? First check the Kernel Driver FAQ at
>>>> http://www.osronline.com/article.cfm?id=256
>>>>
>>>> To unsubscribe, visit the List Server section of OSR Online at
>>>> http://www.osronline.com/page.cfm?name=ListServer
>>>>
>>> —
>>> Questions? First check the Kernel Driver FAQ at
>>> http://www.osronline.com/article.cfm?id=256
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>