Search code examples
cmd

How to stop a cmd file from showing Network error messages


Error Message I want to remove:

I get this error when I run a code that runs a shortcut that's shared over network.

How can I stop cmd script from showing Network Errors like these, even if I know there is an error?


Solution

  • @echo off
    echo.
    echo 1. Add
    echo 2. Remove
    echo.
    set /p var= Type option number here - 
    if %var%==1 (goto :add)
    if %var%==2 (goto :remove)
    if else (goto :EOF)
    
    :add
    reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\ /v RestoreConnection /d 0
    echo.
    echo SUCESSFULLY ADDED!
    timeout /t 2 /nobreak >nul &exit
    
    :remove
    reg delete HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\ /v RestoreConnection
    echo.
    echo SUCESSFULLY REMOVED!
    timeout /t 2 /nobreak >nul &exit
    

    This .bat script could come handy btw. Atleast it's easier than changing the registry manually. You can add and delete the value any time you want, so its convenient. Save this as a (.bat) file and use it...

    Thanks @FiddlingAway for giving reference for the script : )