![]() I spent some time on this last week, but got rabbit-trailed when I followed some documentation that created a CIM class on my system that I couldn't get rid of. ![]() Note, there's also apparently a way to register the event listener permanently though CIM. You'll need to call it through the powershell command (not pwsh since it uses WMIEvent). In theory, you can set this script to run at Windows Login via Task Scheduler, but I haven't tried it. If you run into a problem, check the output. I'm sure there's a PowerShell Core equivalent using CIM, but I haven't tried it that way yet. Note that this needs to run in Windows PowerShell (rather than PowerShell Core) since it uses WMIEvent. Register-WmiEvent -Query $Query -Action $Action -SourceIdentifier USBFlashDriveWSLMount Wsl -u root -e mount -t drvfs $drivePath /mnt/$driveLetter $query = "select * from _InstanceCreationEvent within 5 where TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 2" Run wsl -u root -e mount -t drvfs /mnt/ when the event fires.Register an action when a USB drive is attached.It's not easy, and it probably needs more error handling to be "robust", but I was able to get this to work by creating a PowerShell script to: That will mount the drive if it's available. Add the following to your ~/.bashrc instead: wsl.exe -u root -e mount -t drvfs D: /mnt/d > /dev/null 2>&1 bashrc type of file because having to type in my password every time I open a terminal ![]() And we also need to handle the case when the drive is attached while WSL is already running.First we need to handle the case when WSL starts up while the drive is already attached.It looks to me like this will need two different approachs:
0 Comments
Leave a Reply. |