Link to home
Start Free TrialLog in
Avatar of Bobaran98
Bobaran98Flag for United States of America

asked on

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!
Avatar of Davis McCarn
Davis McCarn
Flag of United States of America image

If you have control over the cameras, why not create an autorun script and place it on the storage media? http://msdn.microsoft.com/en-us/library/bb776824.aspx and http://www.karenware.com/powertools/ptautorun.asp
A couple of benefits:  Your app will automatically run and you will know the camera has been infected when it doesn't.
Avatar of Bobaran98

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of 13598
13598
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you have the company make that change via group policy?  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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?
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!
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.
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?
Thanks!
Brainstorming too:
What about disabling the plug and play service is that an option?
What about disabling and then reenabling after camera is setup?
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?
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!
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!