Programmatic Registry Change - Take No Action when Device Connected

Hello!  I'm developing a DotNet app that uses WIA (Windows Image Aquisition) to grab images from a camera.  That's no problem.  My issue is that whenever a user plugs in their camera, they get (by default) the standard dialog box:  "Device connected - Select the program to launch for this action."  What I want to do is kill that dialog programmatically.  Note that this app will run solely on XP systems.

PLEASE-- I know how to do it manually (go to the camera properties, Events tab, select "Take no action").  I've also seen code for registering my own application to appear in the dialog list.  I've seen other code that captures that dialog box, but only if my app has focus.  None of those options meet my need.  What I need is DotNet code to programmatically change the device connection event to "Take no action."

WHY? you ask.  IS THAT EVEN ETHICAL? you ask.  To answer both questions, my app is for internal company use only, by remote employees who are largely computer illiterate.  I'm trying to prevent the confusion of just one more window popping up.  And believe me, they find this sort of thing very confusing.

If you can tell me this isn't possible-- and I can understand why Windows might not allow it, for security reasons-- that would be fine.  If push comes to shove, I can write a walkthrough to show users how to manually set XP to "Take no action" when they plug their camera in.  But that's a last resort.

Thanks for any help!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Davis McCarnOwnerCommented:
If you have control over the cameras, why not create an autorun script and place it on the storage media? and
A couple of benefits:  Your app will automatically run and you will know the camera has been infected when it doesn't.
Bobaran98Author Commented:
Hi, Davis, thanks for your reply.  I do not have control of the cameras or even the computers-- that's why I'm trying to simplify things here.  All hardware belongs to the company, but exists at remote sites.  I provide our apps from a download site, and remote employees download and install.  I want my app, on running for the first time to disable the camera's default autoplay action (set it to "Take no action")-- preferably to set this behavior for ALL cameras/scanners.
I do not want my app running automatically when a camera is plugged in.  I want nothing to happen.  There are several flavors of my app, often installed on the same machine, and the camera gets accessed by them all.  And that functionality is already in place and working.
This is a registry issue and, I think, a registry fix-- I just can't puzzle out the entries.  Any other thoughts?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Can you have the company make that change via group policy?  
Davis McCarnOwnerCommented:
Here is an article on manipulating the registry using DotNet:
The two registry keys you need to modify are:
I would suggest getting the current values (GetValue) , oring it with 0x04 (hex) which will disable removable device autoplay, and then  writing it back (SetValue).  Remember to do both keys and they need to reboot afterwards (or, at least, rerun explorer)
Bobaran98Author Commented:
Thank you both for your suggestions so far-- still nothing workable, though.
13598-- On that link you gave me, the first option (for suppressing the AutoRun when it launches) isn't what I'm looking for.  I need to disable AutoRun for cameras regardless of whether my app is running.  That solution, as I mentioned in my initial problem statement, doesn't work because the app has to be running and has to have focus (be the top window).  Not viable.
To you both-- I really thought that editing those two registry keys would do the trick, and I've spent way too long now trying to finagle them.  Certainly you would think a USB-connected camera would be treated as a drive.  But no.  Even disabling all (using 0xFF)-- while it does work for CDs, flash drives, and network drives-- fails to affect cameras.  I've tried this on multiple machines to be sure before responding here.
Note that I'm plugging in cameras directly via USB, not using a card reader.  I've seen posts elsewhere to suggest that camera/scanner AutoRun would be controlled by WIA keys (Windows Image Acquisition).  Haven't found a solution yet though.  And I have to be careful... can't just disable WIA, because that's the service I use to get the images in my .NET code.
Thoughts?  Thank you!
Group policy is not an option?
Davis McCarnOwnerCommented:
Cameras are supposed to be treated as removable media devices; so, thank you very much, Mr Gates (mutter, mutter, mutter).
So, OK, there is another registry key which disables based upon the drive letter.  Would that work?
Bobaran98Author Commented:
Sorry, 13598, meant to address that.  No, group policy's not an option... unless, again, you have a way of implementing the change in code (and can show me how to do this in group policy-- because as with the registry, disabling AutoRun in gpedit doesn't affect cameras/scanners).  Manually editing group policy is out since these are remote computers that I have no access to.
Davis... haha.  Gotta love MS!  As for drive letter disabling, I'm not sure if that would help, since cameras don't get assigned a drive letter.  For that matter, I just took a look through Computer Management > Storage, and cameras apparently are not treated as a drive at all.
Folks, I appreciate your persistence working through this with me!
Davis McCarnOwnerCommented:
Yes they are.  Hook up a camera and virtually every one I have ever touched becomes a drive letter for the memory card; usually the first available letter above C.  If yours don't, I'd be awfully surprised.  They don't however get listed as a camera; but, rather as a storage controller and a disk drive.
Bobaran98Author Commented:
I've never experienced that, as far as I know.  And certainly it's not happening right now-- when I plug a camera in via USB, just as when I plug in a scanner, it shows up in My Computer in its own section, called "Scanners and Cameras."  What you're describing sounds like when you take the card out and plug it into a card reader, in which case XP would indeed see it as removable media.
That doesn't mean we're not both right. :-)  It all depends on your hardware.  I wouldn't be at all surprised if some digital cameras are designed (intentionally) so XP sees them as card readers.  Certainly the cameras I've been testing with are older models... maybe this is a newer trend.
Brainstorm mode... It's looking like we'll probably be buying the cameras in bulk here at the home office and sending them out to our field techs.  If we simply make sure to get a camera that detects as a driver letter/removable driver rather than a camera, then we'd be set, right?  Davis, what sort of cameras have you used that exhibited this behavior?  What brands, for example?
Brainstorming too:
What about disabling the plug and play service is that an option?
What about disabling and then reenabling after camera is setup?
Davis McCarnOwnerCommented:
The mere fact that one of the Autoplay options is to Open the Folder..... tells you it is a removeable drive and that setting for autoplay should have dealt with it.  Did you deal with the HKEY_CURRENT_USER part and verify it worked?
Bobaran98Author Commented:
Hey guys-- was out for the weekend.  Back at it now.
Davis, on these cameras, opening the folder is not one of the AutoPlay options.  And I did point out earlier that changing the registry settings have no effect on the cameras.  I can set NoDriveTypeAutoRun to FF, which should disable everything, and everything else is disabled... but not these cameras.  Again, these cameras show up under "Scanners and Cameras" in My Computer.  They're not treated as removeable drives.
NOW... that said, I have acquired another, newer camera to test with, and it has the behavior you've been describing all along.  It shows up as a removable drive (with a drive letter), and the registry change does indeed have an effect on whether the "choose an action" dialog appears when I connect it.  Unfortunately, this device doesn't work with my VB.NET WIA (windows image acquisition) code.  It never gets detected.  I've read online that WIA only works with devices that appear in the "Scanners and Cameras" section-- which, of course, is the cameras I was dealing with earlier and not this one.
I'm currently looking for code that will allow me to access images off this camera model.  If I can't use WIA, that's problematic, since the WIA library offers prebuilt dialogs for previewing, deleting, and otherwise managing the photos on the camera.  Very little extra coding required of me.
Thanks for your patience in helping me work this out!
Bobaran98Author Commented:
Although we never really established a solution within my original scenario (with cameras that appear under "Scanners and Cameras" as opposed to showing up as removeable drives), the registry changes you both suggested work fine as long as the cameras employees use always appear as removeable drives.  I am now working off that assumption, with the commitment to simply buy new cameras of a certain (pretested) model if an employee's camera proves incompatible.  I have written my own dialog to replace WIA, which will parse the contents of all attached drives and will find the directory most likely to contain photos-- so I'm fine with abandoning WIA now.  In short, the experts' answers got us to a solution, if not the original solution sought.  Good enough!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.