Next: OpenThread
From: Mike M. on
Windows XP Pro and Visual Studio 6.0 I need to write a small service that
detects when a USB drive is plugged in so I can run another program from the
removable drive. I have been testing with the Autoplay settings using
TweakUI and such but it isn't as reliable as I would like. And I don't like
the way it functions in some circumstances. Is there a way to register to
receive the detection event or periodically scan for a device?

TIA


From: William DePalo [MVP VC++] on
"Mike M." <nospam(a)someplace.com> wrote in message
news:OvDFYP3wFHA.1256(a)TK2MSFTNGP09.phx.gbl...
> Windows XP Pro and Visual Studio 6.0 I need to write a small service that
> detects when a USB drive is plugged in so I can run another program from
> the
> removable drive. I have been testing with the Autoplay settings using
> TweakUI and such but it isn't as reliable as I would like. And I don't
> like
> the way it functions in some circumstances. Is there a way to register to
> receive the detection event or periodically scan for a device?

Yes, there is a way.

The shell provides a less-than-barely documented function named
SHNotifyChangeRegister() to register a request to be notified of device or
media insertions, removals etc.

As it is a shell function, there may be gotchas when trying to use the
function in a service which - if you follow reasonable security policy -
should not run on the interactive desktop.

You may want to post again in the kernel group

microsoft.public.win32.programmer.kernel

for more information or to see if there are other options.

On your way over you may find this sample useful:

http://www.codeproject.com/shell/shchangenotifyregister.asp

Sadly I couldn't find one the MSDN site.

Regards,
Will


From: Skywing on
You could use RegisterDeviceNotification() - lives in user32 (not shell32),
well documented, and works for both services and programs that have windows.

"William DePalo [MVP VC++]" <willd.no.spam(a)mvps.org> wrote in message
news:O8kwKh3wFHA.664(a)tk2msftngp13.phx.gbl...
> "Mike M." <nospam(a)someplace.com> wrote in message
> news:OvDFYP3wFHA.1256(a)TK2MSFTNGP09.phx.gbl...
>> Windows XP Pro and Visual Studio 6.0 I need to write a small service
>> that
>> detects when a USB drive is plugged in so I can run another program from
>> the
>> removable drive. I have been testing with the Autoplay settings using
>> TweakUI and such but it isn't as reliable as I would like. And I don't
>> like
>> the way it functions in some circumstances. Is there a way to register
>> to
>> receive the detection event or periodically scan for a device?
>
> Yes, there is a way.
>
> The shell provides a less-than-barely documented function named
> SHNotifyChangeRegister() to register a request to be notified of device or
> media insertions, removals etc.
>
> As it is a shell function, there may be gotchas when trying to use the
> function in a service which - if you follow reasonable security policy -
> should not run on the interactive desktop.
>
> You may want to post again in the kernel group
>
> microsoft.public.win32.programmer.kernel
>
> for more information or to see if there are other options.
>
> On your way over you may find this sample useful:
>
> http://www.codeproject.com/shell/shchangenotifyregister.asp
>
> Sadly I couldn't find one the MSDN site.
>
> Regards,
> Will
>
>


From: Mike M. on
Thanks Will. I'll investigate this method.

"William DePalo [MVP VC++]" <willd.no.spam(a)mvps.org> wrote in message
news:O8kwKh3wFHA.664(a)tk2msftngp13.phx.gbl...
> "Mike M." <nospam(a)someplace.com> wrote in message
> news:OvDFYP3wFHA.1256(a)TK2MSFTNGP09.phx.gbl...
> > Windows XP Pro and Visual Studio 6.0 I need to write a small service
that
> > detects when a USB drive is plugged in so I can run another program from
> > the
> > removable drive. I have been testing with the Autoplay settings using
> > TweakUI and such but it isn't as reliable as I would like. And I don't
> > like
> > the way it functions in some circumstances. Is there a way to register
to
> > receive the detection event or periodically scan for a device?
>
> Yes, there is a way.
>
> The shell provides a less-than-barely documented function named
> SHNotifyChangeRegister() to register a request to be notified of device or
> media insertions, removals etc.
>
> As it is a shell function, there may be gotchas when trying to use the
> function in a service which - if you follow reasonable security policy -
> should not run on the interactive desktop.
>
> You may want to post again in the kernel group
>
> microsoft.public.win32.programmer.kernel
>
> for more information or to see if there are other options.
>
> On your way over you may find this sample useful:
>
> http://www.codeproject.com/shell/shchangenotifyregister.asp
>
> Sadly I couldn't find one the MSDN site.
>
> Regards,
> Will
>
>


From: Mike M. on
Thanks Skywing. I'll check this out.

"Skywing" <skywing_NO_SPAM_(a)valhallalegends.com> wrote in message
news:%234HZZs3wFHA.2252(a)TK2MSFTNGP09.phx.gbl...
> You could use RegisterDeviceNotification() - lives in user32 (not
shell32),
> well documented, and works for both services and programs that have
windows.
>
> "William DePalo [MVP VC++]" <willd.no.spam(a)mvps.org> wrote in message
> news:O8kwKh3wFHA.664(a)tk2msftngp13.phx.gbl...
> > "Mike M." <nospam(a)someplace.com> wrote in message
> > news:OvDFYP3wFHA.1256(a)TK2MSFTNGP09.phx.gbl...
> >> Windows XP Pro and Visual Studio 6.0 I need to write a small service
> >> that
> >> detects when a USB drive is plugged in so I can run another program
from
> >> the
> >> removable drive. I have been testing with the Autoplay settings using
> >> TweakUI and such but it isn't as reliable as I would like. And I don't
> >> like
> >> the way it functions in some circumstances. Is there a way to register
> >> to
> >> receive the detection event or periodically scan for a device?
> >
> > Yes, there is a way.
> >
> > The shell provides a less-than-barely documented function named
> > SHNotifyChangeRegister() to register a request to be notified of device
or
> > media insertions, removals etc.
> >
> > As it is a shell function, there may be gotchas when trying to use the
> > function in a service which - if you follow reasonable security policy -
> > should not run on the interactive desktop.
> >
> > You may want to post again in the kernel group
> >
> > microsoft.public.win32.programmer.kernel
> >
> > for more information or to see if there are other options.
> >
> > On your way over you may find this sample useful:
> >
> > http://www.codeproject.com/shell/shchangenotifyregister.asp
> >
> > Sadly I couldn't find one the MSDN site.
> >
> > Regards,
> > Will
> >
> >
>
>


 |  Next  |  Last
Pages: 1 2 3
Next: OpenThread