问题
Have a script in .bat for deliting shares on win7 (without admins shares like ADMIN$ etc.)
@echo off
(wmic path Win32_OperatingSystem get /value|find "ProductType=1" > nul) || (echo [e] Server OS & goto :eof)
setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('wmic share get name /value ^| findstr /r /v "^$"') do (
for /f "tokens=2 delims==" %%b in ("%%a") do (
set VarAdminAllowed=NotAllowed
for %%c in (ADMIN$ IPC$ print$ fax$ A$ B$ 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 %%b == %%c set VarAdminAllowed=Allowed
)
if !VarAdminAllowed! == NotAllowed net share /delete "%%b" /yes
)
)
May be another way to delete shares exist ? P. S. Domain users over 3000+
回答1:
@echo off
setlocal enableextensions disabledelayedexpansion
rem Win32_OperatingSystem class
rem https://msdn.microsoft.com/en-us/library/aa394239%28v=vs.85%29.aspx
( wmic OS where "ProductType=1" | find "Boot" ) >nul 2>nul || (
echo [e] Server OS
goto :eof
)
rem Win32_Share class
rem https://msdn.microsoft.com/en-us/library/aa394435%28v=vs.85%29.aspx
wmic share where "Type < 2147483648" call Delete
Just use the methods exposed by the wmi
class.
来源:https://stackoverflow.com/questions/44404466/delete-shares-excluding-c-d-admin-etc