Changes to System.DeviceAttached/System.DeviceRemoved

Got a good idea? You can suggest new features here.
Post Reply

Add device names and other device data to System.DeviceAttached/System.DeviceRemoved

Yes
14
100%
No
0
No votes
Have no clue what I am talking about
0
No votes
Don't care
0
No votes
 
Total votes: 14

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Tue Feb 21, 2017 6:22 pm

I have found a way to get all kinds of extras into the System.DeviceAttached and System.DeviceRemoved events. because i don't know about you but the very odd combination of vendorId/GUID was not a great means of identification. and has bugged me for a long while

The big one is the actual device name into the event. but I am also able to add a payload that would give you just about every metric available for a specific device.. like mode l#'s serial #'s, drive sizes, volume labels, battery serial numbers, battery life, batter charge, battery runtime. how long it takes the battery to recharge, the list goes on and on and on.

I also want to add an action that would allow you to query the System plugin to see if a device is attached and you could enter the GUID, the vendorId, or the name. and it would return an instance of the device where you would be able to grab the metrics from the device yourself. because all the various devices have all different kinds of metrics.

the events would be specifically keyed to USB plugging and drive insertion. but the action i would add would be for all devices in the system. right down to specific cooling fans. and temperature sensors. This change would break current scripts that people have created but i think the benefits outweigh having to change your scripts. and would most likley make you scripts smaller.

This will also give the ability to do some really cool things like if you have more then one USB drive that uses the drive letter E because you would have information like drive size, and # of partitions, volume label it makes it super simple to launch a slideshow if it's a photo drive, or to launch your movie player if it's a video drive. or even something like this (which i would use myself.) if you have a bunch of VM's the worst thing is having to reclaim empty space on the drive. make a script to mount and unmount a VHD and based on the volume label i give the drive, it would automatically run the reclaiming process. and i wouldn't have to create a thread to sit there wand wait until it finished. put that into a schedule to run once every couple of months. and Now i don't have to go and do it manually. YAY!!!

***EDIT***

This is no longer just keyed to USB insertion and removal. I managed to get a whole lot more added to it as seen below in the next post. I just thought it should be here as well
here is the list of now supported devices
Display Adapters, Keyboards, Mice, HID, USB, Monitors, Serial Ports, Windows Portable Devices, Network Adapters, Volumes, Modems, and BluTeeth Devices.

The GetDevices Action is also working and I just have to finish up the docs on how to use it. drop a line in here if you are interested in checking it out.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Wed Feb 22, 2017 4:09 am

well I have a partial test version if anyone is interested in giving it a go..

I have not complete the device lookup action side of things as of yet. but I believe I have the event bits good.. there could be some bugs. not sure tho. I have expanded the functionality of the events so it is no longer just limited to HID, Monitor, Volumes, and USB.

here is the list of now supported devices.
Display Adapters, Keyboards, Mice, HID, USB, Monitors, Serial Ports, Windows Portable Devices, Network Adapters, Volumes, Modems, and BluTeeth Devices.

The reason for the added device types is because if using just USB you will get names for things you seen in the USB tree of the device Manager. so things like USB Composite device for a webcam instead of the actual cam name.

I have attached the file. you will need to plop it right into YOUR EG INSTALL FOLDER/plugins/System folder. replace the file that is in there
If you like the work I have been doing then feel free to Image

Diz
Experienced User
Posts: 121
Joined: Tue Jan 10, 2017 4:49 pm

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by Diz » Thu Feb 23, 2017 8:32 pm

just tried this and now i get no device change notifications at all! i only tested with usb devices which are a memory stick and 2 different phones

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Fri Feb 24, 2017 10:52 pm

that's very odd it works on my machine... what version of EG are you running? and what version of windows???

I am running this on eg 0.5 Beta 6 and Windows 7 x64
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Fri Feb 24, 2017 10:53 pm

Microsoft does have a very nasty habit of changing GUID's between windows versions. If you are running windows 10 i will have to do some more digging to see if the GUID's have changed at all...

This is the reason why i posted it up here.
If you like the work I have been doing then feel free to Image

Diz
Experienced User
Posts: 121
Joined: Tue Jan 10, 2017 4:49 pm

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by Diz » Sat Feb 25, 2017 4:09 am

i still use windows XP! and the new beta 6 eg. actually i already had to make an xp friendly version of the system plugin script 'PowerBroadcastNotifier.py', but that one spat out some errors, this one doesnt give any output at all! so i guess xp compatibilty is gone now huh? that is sad :( nevermind i will go back to using the beta 6 device change notifier :)

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Sat Feb 25, 2017 3:33 pm

@Diz

You gotta let me know if things aren't working properly we are spanning 6 Windows versions not including service packs. There is bound to be things missed. I really do need to set up a VM for each version. I will get around to it at some point. PM me the changes to the power broadcast notifier so I can take a look see and have them added. And I will also work with ya in getting the device change working. The API for Windows XP is not something that I have specifically looked for and I know Microsoft dropped support for it as well as vista which means they most likely don't have it up on a site. So if you know of somewhere please share. It's not hard to set up some version checking to see what OS is running and to set the proper things in motion for that OS. This the is very reason why I like to toss things up in the forum. I am not sure if you know about EventGhost on Github or not. But we really don't get a lot of activity on it save for the people contributing. But it's the best place to let us know if something is not working properly. I tend to jump on things as soon as I see an issue. And if one person has an issue then it's still an issue. You will never hear from me that "well I have no problems, it must be your setup" if one person has a problem. That's one problem. Too many. But ya have to be patient with me. I'm getting up there in age. Brain works fingers have a hard time. So I tend to have a lot of typos. And I only started programming a year and a half ago. So I am still learning. But I. Never give up. Maybe take a break. But I don't give up. And the more of a challenge it is the more I like it. But if something is not up to par. Go and get a stick smack me with it a few times. And tell me to get my shit together and fix it. LOL
If you like the work I have been doing then feel free to Image

Diz
Experienced User
Posts: 121
Joined: Tue Jan 10, 2017 4:49 pm

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by Diz » Sat Feb 25, 2017 4:42 pm

oh sorry, i didnt mean to sound impatient or anything but as i know even microsoft have dropped all support for xp then i just figured that xp compatibility wasnt gonna happen anymore! lol. so i have had a play with the new device change notifier and its not the guid's, they are the same. the plugin sort of works, in that it gives no errors, but for some reason i think the new triggerevent routine just doesnt output anything at all. not sure why yet, i will have another look tonight.

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Sun Feb 26, 2017 1:42 am

@Diz
We are still supporting XP and Vista. So i am not even sure if pywin32 fully supports XP or vista anymore this was updated. I do not know if Windows XP has the same API for WMI. and you may not be seeing an error because of the use of wv.CallAfter.

wx.CallAfter has to be used in order to keep the creation of the WMI object and querying the object in the same thread. it cannot be initialized from __init__ because that gets called from a different thread then the actual notification that comes in. so when the notification comes in it also performs a wx.CallAfter placing both the creation of the WMI object and the querying of it into the main thread. and sometimes when an error occurs you may not see it. so if you move the creation of the WMI object to __init__ if there is an error it will show up. that is the only reason as to why I think you may not be seeing anything. and the API for hooking the WMI could be different. the API handle i am using is ""winmgmts:"

On another note. I have not fully tested plugging and unplugging a USB flash drive. and that is what windows will see a phone as. So that may be where the issue lies. Try plugging something else in like a webcam or another mouse. It was snowing the night i made this and i wasn't going outside to get my USB cable for my phone :shock:, sorry for that, but some things i am just not willing to do and one of them was getting all geared up for a trek in the 12" of snow at -10f temps for 250 feet to get my cable to bug test a bit of code. :twisted: I figured if there was an issue someone would post that there was one. LOL :D

and as far as the PowerBroadcastNotifier if you could please inform me of what was not working and what you did for a solution i will be more then happy to add it to the code. as i do not have an XP machine It would make it just a wee bit easier for me then having to track down my copy of XP (lord knows where i have that disk) and possibly even have to play around with it to get it running on 2012 hyper-v Server (Oh Goody!!!)

and you didn't sound impatient. I just wanted to put it out there about how i see things. If I don't know it's broke, then I don't know I need to fix it. so any and all information you can provide to help track down the cause of an issue is really helpful. because the possible combinations of hardware/windows/installed software/plugins/Microsoft changing things and not telling anyone. is infinite
If you like the work I have been doing then feel free to Image

Diz
Experienced User
Posts: 121
Joined: Tue Jan 10, 2017 4:49 pm

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by Diz » Sun Feb 26, 2017 4:46 am

oh... errrm... i sent it to you in a pm like you said earlier, did you not get it?

im not really a programmer so i dont really understand all that api and wmi stuff! if the plugin wasnt running properly wouldnt eg spit out big red errors at me? lol... and as for the devices, are you saying they might just not be recognised? they all show up with the beta 6 version as lots of letters and numbers!

ok, wow! i just found my playstation 3 controller and tried that and it works properly with that! so it was just a device recognition issue, but the old plugin recognised them just fine and this new one didnt even register a device had been changed! cant you just make it revert to the old style if a device isnt recognised instead of outputting nothing at all?!! :)

i suspect the output is not exactly what you planned either in this case with ps3 pad... lots of u's about!

06:29:06 System.DeviceAttached.HID-compliant game controller {'status': u'OK', 'description': u'HID-compliant game controller', 'name': u'HID-compliant game controller', 'device_id': u'HID\\VID_045E&PID_0719&IG_00\\7&1F1C2019&0&0000'}

06:28:45 System.DeviceRemoved.HID-compliant game controller {'name': u'HID-compliant game controller', 'device_id': u'HID\\VID_045E&PID_0719&IG_00\\7&1F1C2019&0&0000'}

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Sun Feb 26, 2017 3:50 pm

the u's are supposed to be there. they are informing you it is a unicode encoded string. that's all they mean. when dealing with strings the ascii table has enough characters in it for the English language. and that's it. so unicode strings were made because say like the Chinese language that has over 2000 characters. well the ascii table is not enough.. or any other language for that matter. so u's are a good thing. what this means is that if you have the language on your computer set to Chinese it will actually show the correct characters for your language. so it's only a problem with the portable HDD or USB thumb drive side of things. which has to get handled a little differently because of the use of drive letters. and it may or may not throw tracebacks because of how it has to be implemented. or if i did something wrong that produces no drive letters but the code functions just not in the manner i want and doesn't produce the results i have it set to look for then it will just "bypass" it throwing no errors.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Sun Feb 26, 2017 3:59 pm

now my question for you is if you go into your device manager. and look about. do you see a driver for "Playstation controller" or just the "HID compliant game controller" this i do want to know I want to make sure it is grabbing the right one if there is more then one. for instance. when you plug in a webcam you will get a driver for the actual webcam. but a driver also installs called "USB Composite device" now i think that someone would prefer to the have event show the actual webcam. I have toyed with the idea of having it throw multiple events. and i will probably do this due to the fact my webcam actually install 3 drivers. one for the video capture, one for the microphone and the USB composite device. and at the current moment it only throws an event for the webcam. And it would appear i also have some work to do on the drive side of things. I will have it sorted by the days end. I have also completed the device lookup action. which is nice if you have an event that runs but then in that macro you want to check and see if a device exists to perform some other action. for instance. if you plug in your ps3 controller a macro runs you then check to see if your headset is also plugged in. and if so it will launch your favorite game. just by plugging in your game controller. that would be pretty cool.
If you like the work I have been doing then feel free to Image

Diz
Experienced User
Posts: 121
Joined: Tue Jan 10, 2017 4:49 pm

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by Diz » Sun Feb 26, 2017 4:24 pm

huh? i dont understand that at all... why do we need to see loads of u's? why do we need to know its unicode? we can see its in english! i get that the program needs to know the difference but do we? lol

my device manager just shows 'HID-compliant game controller'

did you get my pm?

User avatar
kgschlosser
Site Admin
Posts: 4209
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by kgschlosser » Mon Feb 27, 2017 12:30 am

I didn't make python. it's how it operates. the u is outside of my control. well not really but if someone is using windows that is set for a language other then English if i convert the unicode string to a normal string as an example 'hello' would look like something like this \x0068\x0065\x006C\x006C\x006F instead of 'hello' in their language. it doesn't affect anything as far as you accessing any of the data. you do not have to specify the u at all.. it is there as a visual indicator that the string has support for multiple languages.

and yes i did get your message. and i have incorporated it into a newer version of the system plugin.. I did modify it a bit because i changed out how the windows version is obtained. and I have also sorted the issue with the drives not showing up. and i also have also made it so that the device notification now shows all device drivers that are added when you plug in a device.. like my phone has 6 drivers associated with it.

I am working on associating a device to a specific drive when it is plugged in.
If you like the work I have been doing then feel free to Image

Diz
Experienced User
Posts: 121
Joined: Tue Jan 10, 2017 4:49 pm

Re: Changes to System.DeviceAttached/System.DeviceRemoved

Post by Diz » Mon Feb 27, 2017 4:39 am

well ok then but it seems to me totally pointless to show a human that a string is unicode but if its out of your control fair enough! :) lol

Post Reply