Forum Discussion

HotCakeX's avatar
Dec 02, 2020
Solved

Show a notification when VPN connection disconnects on its own - built in Windows 10 connection

Show a notification when VPN connection disconnects on its own - PPTP/L2TP/SSTP/IKeV2 - built in Windows 10 connection

 

There needs to be a notification when VPN connection automatically and silently disconnects on its own.

when the VPN server drops the connection or something happens to the VPN server/connection, the VPN on Windows 10 silently turns off and user is not notified, that makes us use the non-VPN connection without us knowing and causes further issue for our work.

the VPN connection I'm referring to is made through Windows 10 settings =>Network & Internet => VPN.

so please add a notification so Windows notifies us when this happens.

 

upvote this suggestion in feedback hub app: https://aka.ms/AAah9mg

 

  • I fully agree this should be standard functionality in windows. But despite 3 years wait and a new OS (W11) still no joy...

    I've found a workaround which works really well. I'm using task scheduler to trigger when VPN disconnects and show a messagebox.

    Please find code below. Save to a XML file. In task scheduler - press import and select XML file. Change the user account to your own.

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2023-02-07T12:16:02.5177569</Date>
        <Author>vervlogen</Author>
        <URI>\VPN disconnect warning</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='Rasman'] and EventID=20268]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
        </EventTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <UserId>S-1-5-21-1234567890-12345678-123456789-1001</UserId>
          <LogonType>InteractiveToken</LogonType>
          <RunLevel>LeastPrivilege</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>run-hidden</Command>
          <Arguments>powershell -WindowStyle hidden -Command "&amp; {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::MsgBox('The VPN has disconnected','OKOnly,SystemModal,Information', 'VPN Disconnect')}"</Arguments>
        </Exec>
      </Actions>
    </Task>
  • Vervlogen's avatar
    Vervlogen
    Copper Contributor

    I fully agree this should be standard functionality in windows. But despite 3 years wait and a new OS (W11) still no joy...

    I've found a workaround which works really well. I'm using task scheduler to trigger when VPN disconnects and show a messagebox.

    Please find code below. Save to a XML file. In task scheduler - press import and select XML file. Change the user account to your own.

    <?xml version="1.0" encoding="UTF-16"?>
    <Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
        <Date>2023-02-07T12:16:02.5177569</Date>
        <Author>vervlogen</Author>
        <URI>\VPN disconnect warning</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='Rasman'] and EventID=20268]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
        </EventTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <UserId>S-1-5-21-1234567890-12345678-123456789-1001</UserId>
          <LogonType>InteractiveToken</LogonType>
          <RunLevel>LeastPrivilege</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>run-hidden</Command>
          <Arguments>powershell -WindowStyle hidden -Command "&amp; {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::MsgBox('The VPN has disconnected','OKOnly,SystemModal,Information', 'VPN Disconnect')}"</Arguments>
        </Exec>
      </Actions>
    </Task>
    • Bleeping_Computer's avatar
      Bleeping_Computer
      Copper Contributor

      Vervlogen 

       

      Hi Vervlogen,

       

      Thank-you very much for posting your work-around notification script.

      I am fundamentally computer illiterate and don't know what to change in the script to make it work

      ie. "Change the user account to your own" 

       

      What exactly should I change?  I've tried changing the author to my login account name but that didn't work.  Would really appreciate your help!

       

      Many thanks,

       

      Bleep

      • HotCakeX's avatar
        HotCakeX
        MVP

        Bleeping_Computer 

        You need to first get your user account's SID:

        (Get-CimInstance -Class win32_userAccount -Filter "name='$env:USERNAME' and domain='$env:COMPUTERNAME'").SID

        And then replace the SID in this line

        <UserId>S-1-5-21-1234567890-12345678-123456789-1001</UserId>

         with your own.

    • HotCakeX's avatar
      HotCakeX
      MVP
      Thank you very much, unfortunately at the moment I'm unable to test it because I use WireGuard and OpenVPN, but I've saved your script for later!
    • HotCakeX's avatar
      HotCakeX
      MVP
      Please upvote the feedback in feedback hub so they will know how many people want this. thanks
  • horton100's avatar
    horton100
    Copper Contributor
    For me, too, this problem is currently looking for a solution to this. It would be nice if Windows would notify us if anything happens to the VPN connection.

Resources