2017-06-07 41 views
0

在有蝙蝠腳本,針對Win7上deliting股(不管理員股像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.域用戶超過3000+

回答

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類公開的方法。

+0

MC ND,非常感謝 –