删除不包括C $ D $ ADMIN $ ...等的股票

时间:2017-06-07 05:47:00

标签: windows batch-file

在.bat中有一个脚本用于在win7上删除共享(没有像ADMIN $等管理员共享。)

@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
    )
)
可能是删除共享存在的另一种方式吗? P. S. Domain用户超过3000 +

1 个答案:

答案 0 :(得分:0)

@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

只需使用wmi类公开的方法即可。