0
@ECHO OFF 
:ProfilDeleter 
SET /P PC=Enter Remote Ip/HostName (for Exit press M): 
if [%PC%]==[] cls && @echo you should fill && goto ProfilDeleter 
if %PC%==m goto :Menu 
if %PC%==M goto :Menu 

SET /p NotToBeDeleted=Your UserName: 
cls 
::HERE NOT WORKING 
SET Profiles=\\%PC%\C$\Users 

PushD "%Profiles%" 
if /I Not "%CD%"=="%Profiles%" (ECHO. Unable to find %Profiles% exiting)&Pause&goto Menu 
FOR /F "Delims=" %%I in ('Dir /AD /B ^|FindStr /I /V /C:"%NotToBeDeleted%" /C:"ADMINI~1" /C:"Public" /C:"Default" /C:"Administrator"') DO RD /Q /S "%%I" 
PopD 
pause 
:Menu 
Exit 

我爲了遠程刪除用戶配置文件夾 取得一批但是我不能對遠程電腦上運行?腳本中的問題在哪裏?

+0

_Not working_沒有診斷價值。請編輯您的問題並添加更多詳細信息:錯誤信息,不良行爲等。嘗試'Dir/AD/B'查看輸出和調試'Dir/AD/B | findstr ...出於'/ F'命令。 – JosefZ

+0

如果我將** SET Profiles = \\%PC%\ C $ \ Users **更改爲** SET Profiles = C:\ Users **腳本。 – serdar

+0

與** SET配置文件= \\%PC%\ C $ \用戶** 我得到「無法找到%配置文件%退出」回聲消息? – serdar

回答

0

閱讀Pushd - UNC Network paths

當指定UNC路徑,PUSHD會創建一個臨時驅動 地圖,然後將使用新的驅動器。
臨時驅動器號 按反向字母順序分配,所以如果Z:空閒,它將首先使用 。

PushD "%Profiles%"

  • "%Profiles%"會繼續爲"\\<PC or IP entered>\C$\Users"
  • "%CD%"將如下(有一些調試ECHO的決心,像"Z:\Users"

更改腳本邏輯):

@ECHO OFF 
SETLOCAL EnableExtensions 
:ProfilDeleter 
SET /P "PC=Enter Remote Ip/HostName (for Exit press M): " 
if "%PC%"=="" (
    rem cls 
    echo you should fill 
    goto :ProfilDeleter 
) 
if /I "%PC%"=="m" goto :Menu 

SET /p "NotToBeDeleted=Your UserName: " 
if "%NotToBeDeleted%"=="" SET "NotToBeDeleted=%UserName%" 
rem cls 
SET "Profiles=\\%PC%\C$\Users" 

echo variables are set as follows: 
echo  Profiles "%Profiles%" 
echo    PC "%PC%" 
echo NotToBeDeleted "%NotToBeDeleted%" 
if exist "%profiles%" (
    PushD "%Profiles%" 
    SETLOCAL EnableDelayedExpansion 
     echo CD after pushd "!CD!" 
    ENDLOCAL 
    rem next `FOR … DIR … |FINDSTR` command requires further debugging IMHO 
    FOR /F "Delims=" %%I in (' 
     Dir /AD /B ^|FindStr /I /V /C:"%NotToBeDeleted%" /C:"All users" /C:"Public" /C:"Default" /C:"Administrator" 
    ') DO (
      rem remove `ECHO` from next line no sooner than debugged 
      ECHO RD /Q /S "%%I" 
     ) 
    PopD 
) else (
    ECHO. Unable to find "%Profiles%" exiting 
    Pause 
    goto Menu 
) 
:Menu 
ENDLOCAL 
goto :eof 

閱讀Debugging your batch files文章。

+0

我得到了同樣的錯誤:( – serdar

+0

我管理去工作吧,但是它非常慢 謝謝@JosefZ – serdar