forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Display Autoplay and reacting to WM_DEVICE REMOVAL/ARRIVAL

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Sat Apr 28, 2007 10:40 am    Post subject: Display Autoplay and reacting to WM_DEVICE REMOVAL/ARRIVAL Reply with quote

Hi guys !

Can anyone help me on these two issues

1. Disabling Autoplay for all drives / drive types
2. Catching device removal / arrival Window messages, ie. whenever an USB stick, CD ROM, DVD, printerport, etc. is inserted/mounted or removed, my VDS app gets notified about the type of device arriving and the drive letter or port that it has been mounted on ?

I have found C++ code that tries to do the same in a Windows service - however this appears not to be working.

I can post the C++ code if it is of any help.


Henrik
Back to top
View user's profile Send private message Send e-mail
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Sun Apr 29, 2007 11:43 am    Post subject: Re: Display Autoplay and reacting to WM_DEVICE REMOVAL/ARRIV Reply with quote

henrywood wrote:
1. Disabling Autoplay for all drives / drive types

There's many different ways to achieve this. Just googling 'Disabling Autoplay for all drives' finds many solutions. i.e. TweakUI, msconfig, group policies, registry edits etc.

Code:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer]
"NoDriveTypeAutoRun"=dword:000000ff


henrywood wrote:
2. Catching device removal / arrival Window messages, ie. whenever an USB stick, CD ROM, DVD, printerport, etc. is inserted/mounted or removed, my VDS app gets notified about the type of device arriving and the drive letter or port that it has been mounted on ?

I've been waiting, and hoping, for someone to reply with a positive answer. Unfortunately I don't think a VDS application can register for messages or receive the type of messages you want.

There is a work around for getting your VDS application notified when a USB device is inserted or removed (or turned On or Off). But it's then up to your application to determine if it was the USB device you want to monitor and whether it was inserted or removed etc.
http://www.vdsworld.com/forum/viewtopic.php?p=28237

henrywood wrote:
I have found C++ code that tries to do the same in a Windows service - however this appears not to be working.

I can post the C++ code if it is of any help.

I'd like to see the C++ code.

_________________
cheers

Dave
Back to top
View user's profile Send private message
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Mon Apr 30, 2007 9:05 am    Post subject: Thank you Reply with quote

Thank you for the reply

I will look into the VDS application you mention.

I have attached the source code.


Henrik



DevService.zip
 Description:
Source code as requested

Download
 Filename:  DevService.zip
 Filesize:  40.68 KB
 Downloaded:  1687 Time(s)

Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Mon Apr 30, 2007 1:44 pm    Post subject: Reply with quote

henrywood,
Have you tried hooking the WM_DEVICECHANGE API message? IMHO the C++ code is a bit overkill just to tell when a device change occurs. If you had a registered copy of GadgetX I have code on my forum that shows how to get a complete list of Devices installed on the PC. I also have code that shows how to get a list of all the running services and their status this includes those that are device drivers. I would still start with trying to hook WM_DEVICECHANGE first and then go from there.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Mon Apr 30, 2007 2:09 pm    Post subject: Reply with quote

hennrywood,
Also just so you know it is not nessary to use the RegisterDeviceNotification API if you are only interested in Ports, Drive Volume, OEM type of devices.

MSDN wrote:
The DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events are automatically broadcast to all top-level windows for port devices. Therefore, it is not necessary to call RegisterDeviceNotification for ports, and the function fails if the dbch_devicetype member is DBT_DEVTYP_PORT. Volume notifications are also broadcast to top-level windows, so the function fails if dbch_devicetype is DBT_DEVTYP_VOLUME. OEM-defined devices are not used directly by the system, so the function fails if dbch_devicetype is DBT_DEVTYP_OEM.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Mon Apr 30, 2007 2:26 pm    Post subject: Reply with quote

[vds]
OPTION MSGEVENT,$0219,WM_DEVICECHANGE

DIALOG CREATE,Device Change,-1,0,240,269
DIALOG ADD,LIST,LIST1,7,8,224,249
DIALOG SHOW

:EVLOOP
wait event
goto @event()


:WM_DEVICECHANGE
info W @msgparams(W)@cr()L @msgparams(L)
goto EVLOOP

[/vds]

This catches it, however @msgparams(W) is always 7 og @msgparams(L) always 0 both on INSERTION and REMOVAL. Also it would appear that I get more than one notification ?

Maybe it is time to get a copy of GadgetX
I may look into it getting a copy tonight

I am looking to get the drive letter/device type and port name/type for both CD/DVD/USB and PRINTER PORTS

If you can help me achiving this with GadgetX, I would almost certainly be buying a copy of GadgetX

Thank you for your help


Henrik
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue May 01, 2007 8:30 pm    Post subject: Reply with quote

Henry,
I guess that your request is enough for me to update the Hooking mechinism in GadgetX the way that I have been wanting too but have not had enough reason to justify the time spent on the update. Wink

Currently with GadgetX you can get the fact that a device was added and removed but because GadgetX does not cache the data that the lParam is pointing too it is unable to tell you what kind of device is being added and removed.

After the updates GadgetX will be able to cache that information. I will keep you posted on the progress.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Wed May 02, 2007 10:37 am    Post subject: Reply with quote

That sounds great !!

Any idea how long this update will take ? (no pressure ! Wink )


Henrik
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Sun May 06, 2007 2:25 pm    Post subject: Reply with quote

Henrik,
I have applied the updates to GadgetX. Very Happy I am currently updating the documentation. As soon as I have the documentation I will upload GadgetX for you to try. I will also include the demo for using the WM_DEVICECHANGE message.

_________________
Home of

Give VDS a new purpose!


Last edited by vdsalchemist on Sun May 06, 2007 2:57 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Sun May 06, 2007 2:49 pm    Post subject: Reply with quote

Thank you very much !

I nearly cannot wait !


Henrik
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Sun May 06, 2007 10:15 pm    Post subject: Reply with quote

Henrik,
Get your credit card out Wink
I have posted the updated version of GadgetX. The update includes a demo called DevChange.dsc... Have fun and let me know if you need any help. I am uploading this new version to the registered users area of my web site as well.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
henrywood
Contributor
Contributor


Joined: 21 Sep 2004
Posts: 66
Location: Copenhagen, Denmark

PostPosted: Mon May 07, 2007 9:10 am    Post subject: Reply with quote

Hi dragonsphere !

I have looked at your DEVCHANGE example included with the new GadgetX and I have a couple of questions:

1. How would I also read the volume name (ie. E: or a portname) on arrival/removal ?

2. How would I read the description/name of the device (USB Kingston etc.)


Also, would I be right in assuming that the example will only notify of USB devices since you have this line ?

%%hDevNotify = @RegisterDeviceNotification(%%Main,@Get(GUID_DEVINTERFACE_USB_DEVICE))

in the code. If so, then how do I change it so any kind of device would be catched ?

I haven't looked too closely at the example yet, since I am not too familar with the GadgetX syntax.


Henrik
Back to top
View user's profile Send private message Send e-mail
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Mon May 07, 2007 1:59 pm    Post subject: Reply with quote

Hi Henrik,
Here are the answers to some of your questions...

1. How would I also read the volume name (ie. E: or a portname) on arrival/removal ?

Ans. I have examples on my Message board that show how to grab info about a device that you can add to this demo.

2. How would I read the description/name of the device (USB Kingston etc.)

Ans. See the answer for number 1.


3. Also, would I be right in assuming that the example will only notify of USB devices since you have this line ?

%%hDevNotify = @RegisterDeviceNotification(%%Main,@Get(GUID_DEVINTERFACE_USB_DEVICE))

in the code.

Ans. No, that line only adds the USB device type however I have no devices on my systems that fall into this type. When testing this demo if I added any type of USB drive Windows reports that I am adding a volume device type. Look at the WNDPROCEVENT it has a IF statement that captures Volume, Port, OEM, USB, and Handle types of devices. The WM_DEVICECHANGE only captures device type changes. It does not report the common names for the devices. Please see Ans. 1.

4. If so, then how do I change it so any kind of device would be catched ?

Ans. There is another Constant for Windows XP and above that is supposed to register your dialog with all device types. The name of the constant is DEVICE_NOTIFY_ALL_INTERFACE_CLASSES and has been defined in the demo. However I have not quite figured out how to use this yet. I am still researching this.



I haven't looked too closely at the example yet, since I am not too familar with the GadgetX syntax

Ans. That is why I am here. You should have received an email invite with your registration information for GadgetX sent approx. May 07,2007 9:00AM Eastern Time. Please direct all other questions to my message board so I can personally and better assist you.

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Aslan
Valued Contributor
Valued Contributor


Joined: 31 May 2001
Posts: 589
Location: Memphis, TN USA

PostPosted: Sat Jun 07, 2008 11:32 pm    Post subject: Reply with quote

Note: While this works with XP it does NOT work with Vista (Even when runas Admin)

Code:
OPTION MSGEVENT,$0219,DEVCHANGE
  DIALOG CREATE,Device Change,-1,0,240,269
  DIALOG ADD,LIST,LIST1,7,8,224,249
  DIALOG SHOW
:evloop
  wait event
  goto @event()
:DEVCHANGE
  LIST ADD,LIST1,@MSGPARAMS(w)
  goto evloop
:Close
  exit


ref: http://forum.vdsworld.com/viewtopic.php?t=3639&highlight=wmdevicechange
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group