WSL2-Network-Fix icon indicating copy to clipboard operation
WSL2-Network-Fix copied to clipboard

Make use of scheduled tasks triggered by HyperV events to execute functions

Open taliesins opened this issue 2 years ago • 0 comments

Its possible to create a scheduled task that gets triggered on hyperv events. This is probably the smoothest way to hook in and run powershell snippets when required. see: https://superuser.com/questions/262799/how-to-launch-a-command-on-network-connection-disconnection

When network card is attached to switch:

Scheduled Task Trigger:

Log: System Source: Hyper-V-VmSwitch Event Id: 232

Payload:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Microsoft-Windows-Hyper-V-VmSwitch" Guid="{67dc0d66-3695-47c0-9642-33f76f7bd7ad}" /> 
  <EventID>232</EventID> 
  <Version>0</Version> 
  <Level>4</Level> 
  <Task>0</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x8000000000000080</Keywords> 
  <TimeCreated SystemTime="2021-11-01T23:48:01.6238111Z" /> 
  <EventRecordID>25479</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="8196" ThreadID="316" /> 
  <Channel>System</Channel> 
  <Computer>tali</Computer> 
  <Security UserID="S-1-5-83-1" /> 
  </System>
- <EventData>
  <Data Name="NicNameLen">74</Data> 
  <Data Name="NicName">6859057B-7070-4426-8777-0C55181D8D90--FC785225-9131-5661-AC0C-3A157C61AE15</Data> 
  <Data Name="NicFNameLen">0</Data> 
  <Data Name="NicFName" /> 
  <Data Name="PortNameLen">36</Data> 
  <Data Name="PortName">C2CE06CC-0A77-4A84-B77A-BECD5B97AB9F</Data> 
  <Data Name="PortFNameLen">36</Data> 
  <Data Name="PortFName">00D5F962-EA19-482C-8D33-902351A56571</Data> 
  <Data Name="SwitchNameLen">36</Data> 
  <Data Name="SwitchName">B6591560-4373-4889-962B-27A4F2442DE5</Data> 
  <Data Name="SwitchFNameLen">3</Data> 
  <Data Name="SwitchFName">WSL</Data> 
  </EventData>
  </Event>

taliesins avatar Nov 02 '21 00:11 taliesins