Nice find.I found this one, which is more succinct:
The Windows 7 Event Log and USB Device Tracking
Static mappings might not be the best solution, as things like drive letters and volume names can tend to be somewhat ephemeric sometimes. By contrast, Device Instance ID and Parent ID for USBSTOR devices will typically remain invariable, which is why the modified Powershell script that I earlier posted relies on the InstanceID for each device to retrieve the Parent ID and display that as an additional column.I'd still have the UI script enumerate a static table for the Device -> Drive / Volume Name mappings, so the executed task doesn't delay on startup querying this data. Especially if you had a USB hub failure, and like 6 devices got disconnected at once.
Here: Windows: Passing parameters to event triggered schedule tasksThere's a trick which I've forgotten, where you write an extended Task XML so your event's data gets directly passed as a variable,
One possible approach to avoid the relatively slow loading/running of a Powershell script is to let the task run wscript.exe in lieu of powershell.exe, and specify a VBScript with the added parameters to go from there, like, make it handle the entire action purely in VBScript code maybe. You could also decide to let your 'first-time initialization/configuration/setup' part of your script run the C# compiler that is part of the .NET Framework that, in turn, is part of Windows 11 by default. Here's an old example batchfile that I wrote to compile one of my simple C# programming experiments into an exe file that, once it has been successfully compiled, can be run by the scheduled task (or better yet... can be run by the VBScript wrapper that is run by this task, passing through the parameters).and the script collapses to a simple table lookup. My current tradeoff is a background watcher saves on startup time, and is near instantaneous but I have to worry about duplicated processes. With a task trigger, I'd have to worry about keeping startup time low as possible.
Batch:
@ECHO OFF
FOR /F "tokens=* USEBACKQ" %%F IN (`REG QUERY "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v InstallPath`) DO SET InstallPath=%%F
SET InstallPath=%InstallPath:*REG_SZ =%
FOR /F "tokens=* Eol= " %%F IN ("%InstallPath%") DO SET "InstallPath=%%F"
IF EXIST "%InstallPath%csc.exe" (ECHO ON) ELSE (ECHO ERROR - Missing csc.exe & GOTO end)
"%InstallPath%csc.exe" /out:"%~dp0\SnippingMax.exe" /target:winexe "%~dp0\SnippingMax.cs" /lib:%InstallPath%WPF /r:UIAutomationTypes.dll,UIAutomationClient.dll
:end
@ECHO Press any key to close this command window . . . & PAUSE >NUL
My Computers
System One System Two
-
- OS
- 11 Home
- Computer type
- Laptop
- Manufacturer/Model
- Asus TUF Gaming F16 (2024)
- CPU
- i7 13650HX
- Memory
- 16GB DDR5
- Graphics Card(s)
- GeForce RTX 4060 Mobile
- Sound Card
- Eastern Electric MiniMax DAC Supreme; Emotiva UMC-200; Astell & Kern AK240
- Monitor(s) Displays
- Sony Bravia XR-55X90J
- Screen Resolution
- 3840×2160
- Hard Drives
- 512GB SSD internal
37TB external
- PSU
- Li-ion
- Cooling
- 2× Arc Flow Fans, 4× exhaust vents, 5× heatpipes
- Keyboard
- Logitech K800
- Mouse
- Logitech G402
- Internet Speed
- 20Mbit/s up, 250Mbit/s down
- Browser
- FF
-
- Operating System
- 11 Home
- Computer type
- Laptop
- Manufacturer/Model
- Medion S15450
- CPU
- i5 1135G7
- Memory
- 16GB DDR4
- Graphics card(s)
- Intel Iris Xe
- Sound Card
- Eastern Electric MiniMax DAC Supreme; Emotiva UMC-200; Astell & Kern AK240
- Monitor(s) Displays
- Sony Bravia XR-55X90J
- Screen Resolution
- 3840×2160
- Hard Drives
- 2TB SSD internal
37TB external
- PSU
- Li-ion
- Mouse
- Logitech G402
- Keyboard
- Logitech K800
- Internet Speed
- 20Mbit/s up, 250Mbit/s down
- Browser
- FF