Skip to content

Instantly share code, notes, and snippets.

@rpatterson
Forked from filimonov/replug_vbox_network.cmd
Last active August 27, 2023 08:49
Show Gist options
  • Save rpatterson/bd6f33fc109ab29df3fa265d8ebb3907 to your computer and use it in GitHub Desktop.
Save rpatterson/bd6f33fc109ab29df3fa265d8ebb3907 to your computer and use it in GitHub Desktop.
"Replug" the cable of running VirtualBox VM (network freeze in guest VM after host windows hybernate - awake)
@echo off
set VboxManageEXE="%VBOX_MSI_INSTALL_PATH%VBoxManage.exe"
set ListRunningVMS=%VboxManageEXE% list runningvms
for /f tokens^=3^,5^ delims^=^"{} %%p in ('%ListRunningVMS%') do (
echo "%%p"
REM Order here seems to be important. When I did `nicpromisc1 deny` then
REM `nicpromisc1 allow-all` inside the 2 `setlinkstate1` commands, the
REM `VBoxManage.exe` process would hang and seemed to lose it's connection to the
REM VirtualBox servcice or some such.
%VBoxManageEXE% controlvm %%p nicpromisc1 deny
%VBoxManageEXE% controlvm %%p setlinkstate1 off
%VBoxManageEXE% controlvm %%p setlinkstate1 on
%VBoxManageEXE% controlvm %%p nicpromisc1 allow-all
)
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-08-08T11:46:34.3582137</Date>
<Author>HOST\Adminstrator</Author>
<Description>Reconnect VirtualBox guest network connections when a change in the host networking interferes with guest network connectivity.</Description>
<URI>\VBox - Replug Guests</URI>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="System"&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Microsoft-Windows-NDIS'] and EventID=10400]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
</EventTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-2497750225-423207635-496948950-1002</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\tools\replug_vbox_network\replug_vbox_network.cmd</Command>
</Exec>
</Actions>
</Task>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment