1

I want a virtual panic button for network disconnects and problems so I can press a key combination at any time and have the computer autodetect network problems or reset the adapter.

I found this on creating a keyboard shortcut: https://lifehacker.com/5783366/how-to-create-a-keyboard-shortcut-to-launch-anything-in-windows

Did some digging on the network diagnostics and found https://blogs.msdn.microsoft.com/mattbie/2010/11/09/running-a-troubleshooter-from-the-command-line/

msdt.exe /id NetworkDiagnosticsWeb ==> brings up an interactive prompt. I don't want an interactive prompt, I want to bring up a tool that will start fixing the network connection ASAP with no manual intervention.

If the question remains unclear: I need to create a shortcut or batch that invokes completely automatic network repair so I can link it to a keyboard shortcut.

1
  • Does whatever problem that you have that gets solved with the troubleshooter also get resolved by disabling / enabling the adapter? I think that would clear most things and should be relatively easy to script.
    – Paul
    Jul 2, 2018 at 2:16

2 Answers 2

2

Below is a batch script that will emulate the keyboard strokes to manipulate the GUI window titled "Internet Connections" that pops up when msdt.exe /id NetworkDiagnosticsWeb is run.

Essentially it will start the msdt.exe /id NetworkDiagnosticsWeb command, ensure the Internet Connections titled window is active, wait 2 seconds, press Tab twice, Enter once, pause 2 seconds, and then press Enter again to ensure it starts troubleshooting immediately.

enter image description here

enter image description here


Batch Script

@ECHO OFF

start "" msdt.exe /id NetworkDiagnosticsWeb
ping -n 2 127.0.0.1 > nul

:VBSDynamicBuild
SET TempVBSFile=%tmp%\~tmpSendKeysTemp.vbs
IF EXIST "%TempVBSFile%" DEL /F /Q "%TempVBSFile%"
ECHO Set WshShell = WScript.CreateObject("WScript.Shell") >>"%TempVBSFile%"
ECHO Wscript.Sleep 500                                    >>"%TempVBSFile%"
ECHO WshShell.AppActivate "Internet Connections"          >>"%TempVBSFile%"
ECHO Wscript.Sleep 2000                                   >>"%TempVBSFile%"
ECHO WshShell.SendKeys "{TAB 2}{ENTER}"                   >>"%TempVBSFile%"
ECHO Wscript.Sleep 2000                                   >>"%TempVBSFile%"
ECHO WshShell.SendKeys "{ENTER}"                          >>"%TempVBSFile%"

CSCRIPT //nologo "%TempVBSFile%"
EXIT

Further Resources

3
  • Is it possible to make the VBS script a static file instead of dynamically creating it via temp-file each time? Also, wouldn't the AppActivate steal focus from the currently active program? The panic button needs to do all the repair in the background without interrupting the active program. Jul 2, 2018 at 13:59
  • Another dangerous thing about this solution: It generates automated key presses. If someone uses this solution to help with connectivity to an online game (which I'm sure will happen sooner or later), low-quality cheat/bot detection software might flag the scripted key commands as a bot and the end-user could be banned Jul 2, 2018 at 15:13
  • This solution emulates key presses using Windows api essentially hooked in via the vbscript using all Windows native non-third party solution. If there's a game that runs on Windows that sense pressing keyboard keys is dangerous, then that implies a poor design for a game on such a platform. There is nothing dangerous about using this Windows native solution and logic to run on a Windows OS. Dec 9, 2020 at 12:46
1

You can use the PowerShell Get-TroubleshootingPack Cmdlet to take you through the process of creating an answer file to later use with Invoke-TroubleshootingPack Cmdlet to automate.


Steps: Creating and Running Manually

1. PowerShell (create answer file)

$aFile = "C:\Folder\Path\AudioAnswerFile.xml"
Get-TroubleshootingPack -Path "C:\Windows\diagnostics\system\Networking" -AnswerFile $aFile

Options to pick during answer file creation

Important: I only picked what I think I needed to pick but do further testing and put more time and thought into each answer just in case you see something applicable in your case.

  • [1] Web Connectivity
  • [1] Troubleshoot my connection to the Internet
  • [1] TCP
  • [1] I'm trying to reach a specific website or folder on a network
  • Pick [x] Exit for all the rest of the answers and press Enter

    enter image description here

    enter image description here


Answer File Content

Note: *Now that you have an answer file, you can use it to point to jobs that you can automate or create shortcuts to run as a batch as I'll talk about with more detail below.

<?xml version="1.0" encoding="UTF-8"?>
<Answers Version="1.0">
  <Interaction ID="IT_EntryPoint">
    <Value>HTTP</Value>
  </Interaction>
  <Interaction ID="IT_WebChoice">
    <Value>Internet</Value>
  </Interaction>
  <Interaction ID="IT_Protocol">
    <Value>6</Value>
  </Interaction>
  <Interaction ID="IT_DefaultConnectivityInitialChoice">
    <Value>HTTPorUNC</Value>
  </Interaction>
</Answers>

2. PowerShell (run diagnostic process)

Note: The $aFile variable value should point to the answer file you just created in #1 above. The $dFolder variable value should be a folder to check for the results of the diagnostic after it runs.

$aFile = "C:\Folder\Path\AudioAnswerFile.xml"
$dFolder = "C:\Folder\Path\Diag"
$var = Get-TroubleshootingPack -Path "C:\Windows\diagnostics\system\Networking"
Invoke-TroubleshootingPack -Pack $v -AnswerFile $aFile -Unattended -Result $dFolder

Results

Now open up the result files from this command you invoked with the answer file by going to the folder specified in the $dFolder variable value and you'll have some files you can further analyze.

Result Folder Files

675B09EE-5DE8-4AF5-B10D-07DB894902D2.Diagnose.0.etl
DebugReport.xml
NetworkConfiguration.cab
ResultReport.xml
results.xsl

enter image description here


Put it all in a Batch File

Note: This expects the answer file to be already configured and in a readable location for the Invoke-TroubleshootingPack cmdlet to utilize so this is what you create with the above step #1. Other than that, you only need to set the AnswerFile= and the DiagFolder= values to be valid locations you can write to.

@ECHO OFF

SET "AnswerFile=C:\Folder\Path\AudioAnswerFile.xml"
SET "DiagFolder=C:\Folder\Path\Diag"

CALL :PowerShell
CD /D "%PowerShellDir%"
Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"

:PowerShell
SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
SET PSScript=%temp%\~tmpNtwkDiagTrblsht.ps1
IF EXIST "%PSScript%" DEL /Q /F "%PSScript%"
ECHO $aFile = "%AnswerFile%">"%PSScript%"
ECHO $dFolder = "%DiagFolder%">>"%PSScript%"
ECHO $var = Get-TroubleshootingPack -Path "C:\Windows\diagnostics\system\Networking">>"%PSScript%"
ECHO Invoke-TroubleshootingPack -Pack $var -AnswerFile $aFile -Unattended -Result $dFolder>>"%PSScript%"
GOTO :EOF

Further Run Validation

After this process runs you should see in the Windows Event Viewer of the System log and Event ID 4100 from the "Diagostics-Neworking" source with an "Information Level" message indicating

"The Network Diagnostics Framework has completed the diagnosis phase of operation, but no network problem was identified."

enter image description here


Further Resources

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .