1
So I would like to schedule a task to run a specific command when a certain hardware (usb) device is unplugged, then another command when it is plugged in.
The commands:
#Unplug
nircmd monitor off
#Plug in
nircmd monitor on
I want this to use as little resources as possible (to keep scripting to a minimum, e.g. I'd like to avoid setting up a constantly running background script, task scheduler by itself should be able to do this job), I'd also like to avoid installing 3rd party software if it can be avoided.
Just about all the information I was able to gather is that there is a logfile C:\Windows\inf\setupapi.dev.log which logs all "Device install messages" (Plugged in) but it does not seem to track unplugs.
According to this file the device ID in question is USB\VID_1B1C&PID_1B11 (can confirm that on linux the device ID is also 1B1C:1B11, that's how I knew which device I was looking for in the first place, god bless lsusb right?)
This gives me that in task scheduler I should probably be able to set up a "plug-in" task based around the setup api, but since I'm actually not familiar with the task scheduler I don't know how (and more specifically, don't know what "Event ID" I would use)
Where will I find device disconnect events? And how do I make task viewer execute my desired commands for each event?
I sorta solved this, Linux has a fairly easily accessible function for running commandswhen specific devices get plugged in or unplugged. So I created a file on a shared storage device both systems can access and had linux edit it everytime the keyboard got plugged in, while on windows I have a batch file running in the background looking for changes to this file and doing various things based on what the file says. Here is the script I used: https://pastebin.com/MnLTcwPp (the file that linux edits is at G:\Switch) this is how I duct-taped my way around the issue.
– Cestarian – 2017-07-15T21:34:23.757