Delete batch for default share

Time:2020-2-12
Copy codeThe code is as follows:
@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: list the existing partitions first, and then delete the shares named by the partition name one by one;
:: prevent the admin $share from reloading at the next boot by modifying the registry;
:: IPC $share requires administrator permission to be successfully removed
::
: JM changed on May 12, 2006
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Title Default share remover
color 1f
echo.
echo ——————————————————
echo.
Echo starts to delete the default share under each partition
echo.
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do @(
if exist %%a:\nul (
Net share%% a $/ delete > nul 2 > nul & & echo successfully deleted the default share named%% a $; the default share named%% a $does not exist
)
)
Net share admin $/ delete > nul 2 > nul & & echo successfully delete the default share named admin $. The default share named admin $does not exist
echo.
echo ——————————————————
echo.
Net stop server / Y > nul 2 > nul & & echo server service stopped
Net start server > nul 2 > nul & & echo server service started
echo.
echo ——————————————————
echo.
Echo modifies the registry to change the system default settings
echo.
Echo is creating the registry file
echo Windows Registry Editor Version 5.00> c:\delshare.reg
:: disable admin $sharing through the registry to prevent loading again after restart
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters]>> c:\delshare.reg
echo “AutoShareWks”=dword:00000000>> c:\delshare.reg
echo “AutoShareServer”=dword:00000000>> c:\delshare.reg
:: to delete the IPC $share, this function needs the administrator permission to be deleted successfully
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]>> c:\delshare.reg
echo “restrictanonymous”=dword:00000001>> c:\delshare.reg
Echo is importing the registry file to change the system default settings
regedit /s c:\delshare.reg
Del C: \ delshare.reg & & echo temporary file has been deleted
echo.
echo ——————————————————
echo.
The echo program has successfully removed all default shares
echo.
Echo press any key to exit
pause>nul