此批次檔會損壞/阻止 Windows 10 啟動嗎?

此批次檔會損壞/阻止 Windows 10 啟動嗎?

下面的腳本中是否有任何內容.bat可以刪除/損壞任何 Windows 10 系統檔案並阻止它們啟動,從而導致啟動循環?重新啟動後,執行以下命令後.bat,Windows 將無法啟動並顯示Critical Service Failed

  • 我以管理員身份運行.bat,既從閃存驅動器,然後從C:,並打開一個 Cmd 終端,文件名是不是在正在處理的閃存驅動器上,這很可疑:
    takeown /f "H:\PVR" /r
    icacls "H:\PVR" /reset /t
    
    for /r "H:\PVR" %%i in (*.ts *.tsv) do move "%%i" "H:\PVR"
    
    cd /d "H:\PVR"
    ren *.tsv *.ts
    
    for /f "delims=" %%d in ('dir /ad /b') do @rd /q /s "%%d"
    setlocal EnableDelayedExpansion
    
    for %%a in (*.ts *.tsv) do (
      set name=%%~Na
      set num=00!random!
      set newName=!!name:~-17!
      ren "%%a" "!newName!%%~Xa"
    )
    
    我將這個腳本組合在一起,結合在這裡和其他地方找到的幾個命令,以便處理.ts來自我的 DVBT-T2 接收器的閃存驅動器上的錄音,其想法是:
    1. H:\PVR獲得其所有內容的許可
    2. .tsv錄音移出子資料夾,刪除子資料夾
    3. .tsv副檔名重命名為.ts
    4. 刪除檔案名稱中的前 17 個字符,因為我不喜歡接收器的前綴格式

我該如何解決這個問題?

答案1

....然後打開一個 CMD 窗口,我看到正在處理不在我的閃存驅動器中的文件名,這很可疑...

  1. H:

    cd /d H:\
    

  2. 如果cd /d H:\返回 non- 0,操作符將執行 後的下一個命令||,使批次腳本執行到文件末尾 [ goto :eOf],結束執行而不對其他資料夾/文件進行任何操作:

    cd /d H:\ || goto :eOf
    

  3. 如果最後一個命令成功返回,它將執行以下takeown命令:icaclsH:

    %__AppDir__%takeown.exe /f H:\PVR\. /r
    %__AppDir__%icacls.exe H:\PVR\. /reset /t
    

    為了takeownicals命令,使用暫停來查看螢幕:

    :: # One space before  ^  and no space and/or another character after  ^  :
       %__AppDir__%takeown.exe /f .\PVR\. /r | <nul ^
       %__AppDir__%Findstr.exe "(or.*):" & %__AppDir__%timeout.exe /t -1
    
       %__AppDir__%icacls.exe .\PVR\. /reset /t |  <nul ^
       %__AppDir__%Find.exe "files; Fai" & %__AppDir__%timeout.exe /t -1
    

    要刪除逾時:

    %__AppDir__%takeown.exe /f .\PVR\. /r && %__AppDir__%icacls.exe .\PVR\. /reset /t
    

  4. Sort以反向模式列出 [ ] 資料夾/樹 [ /r] 以取得目錄樹中的最後一個子資料夾/目錄,並在可能的情況下移動檔案並刪除目前目錄:

    for /f usebacktokens^=* %i in (`dir /b /s /ad-h H:\PVR\.^|%__AppDir__%Sort.exe /r
    
    $ Dir /b /s /ad-h D:\PVR|%__AppDir__%Sort.exe /r
    
      H:\PVR\tmp
      H:\PVR\Dir 003\tmp
      H:\PVR\Dir 003
      H:\PVR\Dir 002\tmp
      H:\PVR\Dir 002
      H:\PVR\Dir 001\tmp
      H:\PVR\Dir 001
      H:\PVR\Dir 000\tmp
      H:\PVR\Dir 000
    

  5. 對於循環中的每個資料夾,移動*.ts?文件,應用到*.ts以及*.tsv其中的文件\PVR\.;如果沒有發生錯誤[正在使用的檔案/資料夾等],則刪除資料夾,否則重新命名檔案:( .\PVR\*.tsv*.ts)

    move "%%~fi\*.ts?" H:\PVR\ && rd "%%~fi" && rename H:\PVR\*.tsv *.ts
    
    move "%%~fi\*.ts?" H:\PVR\ if return 0 do:
      rd "%%~fi" &&  if return 0 do:
        rename H:\PVR\*.tsv *.ts

    我假設沒有其他*.ts資料夾中的文件,您需要刪除該資料夾[ @rd /q /s "%%d"];如果不是這種情況,請將最後幾行替換為:

    for /f usebacktokens^=* %%i in (`Dir /b /s /ad-h H:\PVR^|%__AppDir__%Sort.exe /r
      `)do ( move "%%~fi\*.tsv" D:\PVR\. && move "%%~fi\*.ts" H:\PVR\.
      ) && ( rmDir /s /q "%%~fi" && rename D:\PVR\*.tsv *.ts )
    

  6. 若要在同一行上並在執行時間使用新定義的變數來取得值,請呼叫cmd /v /c !Newly defined variable!;這就是透過將名稱長度限制為最多 17 個字元來重新命名檔案的方法。!_new:~-17!(與最後 17 個字元相同)

    set "_new=%%~ni" && in the same line use: cmd.exe /v:on /c rename "%%~fi" "!_new:~-17!%%~xi"
    • where我個人的偏好是為了方便返回文件的完整路徑而使用;與 不同的是dir /b,它不顯示小寫字串:
      for /f useback^tokens^=* %%i in (`2^>nul %__AppDir__%where.exe "H:\PVR":"*.ts*"
      `)do set "_new=%%~ni" && cmd.exe /v:on /c rename "%%~fi" "!_new:~-17!%%~xi"
      
    • 我添加了useback(縮寫為usebackq)以避免檔案名稱/路徑中可能存在任何特殊字元時出現意外行為,即使未發布字串/佈局組成檔案名



要處理移動/重命名檔案:

@echo off

cd /d H:\.. || goto :eof
setlocal Enabledelayedexpansion

%__AppDir__%takeown.exe /f .\PVR\. /r | <nul ^
  %__AppDir__%Findstr.exe "(or.*):" & %__AppDir__%timeout.exe /t -1

%__AppDir__%icacls.exe .\PVR\. /reset /t |  <nul ^
  %__AppDir__%Find.exe "files;.Fa" & %__AppDir__%timeout.exe /t -01

for /f usebacktokens^=* %%i in (`Dir /b /s /ad-h H:\PVR^|%__AppDir__%Sort.exe /r
  `)do move "%%~fi\*.ts?" H:\PVR\ && rd "%%~fi" && rename H:\PVR\*.tsv *.ts

for /f useback^tokens^=* %%i in (`2^>nul %__AppDir__%where.exe "H:\PVR":"*.ts*"
  `)do set "_new=%%~ni" && cmd.exe /v:on /c rename "%%~fi" "!_new:~-17!%%~xi"

endlocal & %__AppDir__%timeout.exe /t -1 | echo\iS dONE! & goto :eof || exit /b
  • 輸出:
      H:\PVR\tmp\F0HZCERYIEYKY--U0O69.ts
      H:\PVR\tmp\4-W5N0-6QDOWYAS-YYW-.ts
      H:\PVR\tmp\-PD2MDWHFIL5VP0DWCN8.tsv
      H:\PVR\tmp\SZAAC--91GQCH7OD9-0P.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\tmpi" Moved: tmp\*.ts?
    
      H:\PVR\Dir 000\tmp\I9aKTe38uRqcmkh2B7GF.ts
      H:\PVR\Dir 000\tmp\BBPcfN7R9jg1ESsgHsnA.ts
      H:\PVR\Dir 000\tmp\FRAEKeG1HnMZTmBpY6CB.tsv
      H:\PVR\Dir 000\tmp\EHuI3OiwSRGZWg7fsxsT.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 000\tmpi" Moved: tmp\*.ts?
    
      H:\PVR\Dir 001\tmp\HZH4jcvj2GvQzf7og5h3.ts
      H:\PVR\Dir 001\tmp\EHRR1jKp3owr4lIsZZre.ts
      H:\PVR\Dir 001\tmp\1c0sB7o881uCGiYZUnvh.tsv
      H:\PVR\Dir 001\tmp\PnDUHnrCAGeUB3RRnwF5.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 001\tmpi" Moved: tmp\*.ts?
    
      H:\PVR\Dir 002\tmp\nqRuQhA9WrXvPk7i2ywt.ts
      H:\PVR\Dir 002\tmp\7b4hGoKaA9HxiSXtbpAT.ts
      H:\PVR\Dir 002\tmp\Y6PbfweT6aSgDiDDCVdU.tsv
      H:\PVR\Dir 002\tmp\qvnIDtkY7uKtfcgStHzq.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 002\tmpi" Moved: tmp\*.ts?
    
      H:\PVR\Dir 003\tmp\wnAVPzdos4RWjrJTt9cr.ts
      H:\PVR\Dir 003\tmp\EXDlfbAqCyfB23l7ZZHz.ts
      H:\PVR\Dir 003\tmp\lgAduikvz4vlF1PWA892.tsv
      H:\PVR\Dir 003\tmp\JcBmygrENpU4kEOOIFqP.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 003\tmpi" Moved: tmp\*.ts?
    
      H:\PVR\Dir 000\SvRxVxF6ZDr7a8R5F9z5.ts
      H:\PVR\Dir 000\1tZDpWwpCVNqrxwr993C.ts
      H:\PVR\Dir 000\BXKSG8q0vo3bXCgaNr7K.tsv
      H:\PVR\Dir 000\qtPe80WQRRrms1Iga1i3.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 000i" Moved: Dir 000\*.ts?
    
      H:\PVR\Dir 001\NXGbTP1AlPxJGRPWaUJx.ts
      H:\PVR\Dir 001\Q2Eq97QpY7XQ7reWjUMi.ts
      H:\PVR\Dir 001\UEAkSw76WV9j0494Lpvv.tsv
      H:\PVR\Dir 001\IFBoWCY483HQE94fpCHU.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 001i" Moved: Dir 001\*.ts?
    
      H:\PVR\Dir 002\4nSfuQtqqOF6rPrs9TKb.ts
      H:\PVR\Dir 002\iNEIDXVdvKkN7abkFZJj.ts
      H:\PVR\Dir 002\ygWGThdkefADZpMKWq30.tsv
      H:\PVR\Dir 002\GLLcbLS8QZngJSDfM9k4.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 002i" Moved: Dir 002\*.ts?
    
      H:\PVR\Dir 003\i1wW84pUm5TEGCWTueFw.ts
      H:\PVR\Dir 003\N7s3dLHI5QzdrkGZJJju.ts
      H:\PVR\Dir 003\T1lQu7bcvmQepdh8iVzp.tsv
      H:\PVR\Dir 003\izNYHYHzFf4moJZPcOJv.tsv
        4 file(s) moved.
    
    Removed: "H:\PVR\Dir 003i" Moved: Dir 003\*.ts?
    
$ where /r .\PVR *.*

  H:\PVR\YHYHzFf4moJZPcOJv.ts
  H:\PVR\I51RPV68L-6MKLEHV.ts
  H:\PVR\-IE2WZ5MGZ0NOYAC8.ts
  H:\PVR\MYVS0GIQKLSZ99-PI.ts
  H:\PVR\1WMI4-W-0DH2C9V9O.ts
  H:\PVR\ZCERYIEYKY--U0O69.ts
  H:\PVR\5N0-6QDOWYAS-YYW-.ts
  H:\PVR\2MDWHFIL5VP0DWCN8.ts
  H:\PVR\AC--91GQCH7OD9-0P.ts
  H:\PVR\KTe38uRqcmkh2B7GF.ts
  H:\PVR\cfN7R9jg1ESsgHsnA.ts
  H:\PVR\EKeG1HnMZTmBpY6CB.ts
  H:\PVR\I3OiwSRGZWg7fsxsT.ts
  H:\PVR\4jcvj2GvQzf7og5h3.ts
  H:\PVR\R1jKp3owr4lIsZZre.ts
  H:\PVR\sB7o881uCGiYZUnvh.ts
  H:\PVR\UHnrCAGeUB3RRnwF5.ts
  H:\PVR\uQhA9WrXvPk7i2ywt.ts
  H:\PVR\hGoKaA9HxiSXtbpAT.ts
  H:\PVR\bfweT6aSgDiDDCVdU.ts
  H:\PVR\IDtkY7uKtfcgStHzq.ts
  H:\PVR\VPzdos4RWjrJTt9cr.ts
  H:\PVR\lfbAqCyfB23l7ZZHz.ts
  H:\PVR\duikvz4vlF1PWA892.ts
  H:\PVR\mygrENpU4kEOOIFqP.ts
  H:\PVR\xVxF6ZDr7a8R5F9z5.ts
  H:\PVR\DpWwpCVNqrxwr993C.ts
  H:\PVR\SG8q0vo3bXCgaNr7K.ts
  H:\PVR\e80WQRRrms1Iga1i3.ts
  H:\PVR\bTP1AlPxJGRPWaUJx.ts
  H:\PVR\q97QpY7XQ7reWjUMi.ts
  H:\PVR\kSw76WV9j0494Lpvv.ts
  H:\PVR\oWCY483HQE94fpCHU.ts
  H:\PVR\fuQtqqOF6rPrs9TKb.ts
  H:\PVR\IDXVdvKkN7abkFZJj.ts
  H:\PVR\GThdkefADZpMKWq30.ts
  H:\PVR\cbLS8QZngJSDfM9k4.ts
  H:\PVR\W84pUm5TEGCWTueFw.ts
  H:\PVR\3dLHI5QzdrkGZJJju.ts
  H:\PVR\Qu7bcvmQepdh8iVzp.ts
    is done!


若要重現上述程式碼的測試場景,請取得一個免費的隨身碟,並取代對應的磁碟機號碼:

@echo off

cd /d H:\.. || goto :eof
setlocal Enabledelayedexpansion

  :: #  create folder for sample/test...

    :: #  H:\
    :: #  \---PVR
    :: #    +---tmp
    :: #    +---Dir 000
    :: #    |  \---tmp
    :: #    +---Dir 001
    :: #    |  \---tmp
    :: #    +---Dir 002
    :: #    |  \---tmp
    :: #    \---Dir 003
    :: #    |  \---tmp

:: # make folders ".\PVR\tmp\." and ".\PVR\Dir 000\tmp\."
  mkdir ".\PVR\tmp\."   ".\PVR\Dir 000\tmp\."

:: # make folders ".\PVR\Dir 001\tmp\." and ".\PVR\Dir 002\tmp\." and ".\PVR\Dir 003\tmp\."
  mkdir ".\PVR\Dir 001\tmp\."   ".\PVR\Dir 002\tmp\."   ".\PVR\Dir 003\tmp\."

  :: # Dir /b /s /ad-h /o-d outputs:
  :: # H:\PVR
  :: # H:\PVR\tmp
  :: # H:\PVR\Dir 000
  :: # H:\PVR\Dir 001
  :: # H:\PVR\Dir 002
  :: # H:\PVR\Dir 003
  :: # H:\PVR\Dir 000\tmp
  :: # H:\PVR\Dir 001\tmp
  :: # H:\PVR\Dir 002\tmp
  :: # H:\PVR\Dir 003\tmp

:: # Show folder the tree/dir created above and list folders
  %__AppDir__%tree.com /a /f .
  %__AppDir__%Timeout.exe  -1 | dir /b /s /ad-h /o-d

echo\UD5I51RPV68L-6MKLEHV.ts >".\PVR\UD5I51RPV68L-6MKLEHV.ts"
echo\5F5-IE2WZ5MGZ0NOYAC8.ts >".\PVR\5F5-IE2WZ5MGZ0NOYAC8.ts"
echo\UY6MYVS0GIQKLSZ99-PI.tsv >".\PVR\UY6MYVS0GIQKLSZ99-PI.tsv"
echo\QA01WMI4-W-0DH2C9V9O.tsv >".\PVR\QA01WMI4-W-0DH2C9V9O.tsv"

echo\F0HZCERYIEYKY--U0O69.ts >".\PVR\tmp\F0HZCERYIEYKY--U0O69.ts"
echo\4-W5N0-6QDOWYAS-YYW-.ts >".\PVR\tmp\4-W5N0-6QDOWYAS-YYW-.ts"
echo\-PD2MDWHFIL5VP0DWCN8.tsv >".\PVR\tmp\-PD2MDWHFIL5VP0DWCN8.tsv"
echo\SZAAC--91GQCH7OD9-0P.tsv >".\PVR\tmp\SZAAC--91GQCH7OD9-0P.tsv"

echo\SvRxVxF6ZDr7a8R5F9z5.ts >".\PVR\Dir 000\SvRxVxF6ZDr7a8R5F9z5.ts"
echo\1tZDpWwpCVNqrxwr993C.ts >".\PVR\Dir 000\1tZDpWwpCVNqrxwr993C.ts"
echo\BXKSG8q0vo3bXCgaNr7K.tsv >".\PVR\Dir 000\BXKSG8q0vo3bXCgaNr7K.tsv"
echo\qtPe80WQRRrms1Iga1i3.tsv >".\PVR\Dir 000\qtPe80WQRRrms1Iga1i3.tsv"

echo\I9aKTe38uRqcmkh2B7GF.ts >".\PVR\Dir 000\tmp\I9aKTe38uRqcmkh2B7GF.ts"
echo\BBPcfN7R9jg1ESsgHsnA.ts >".\PVR\Dir 000\tmp\BBPcfN7R9jg1ESsgHsnA.ts"
echo\FRAEKeG1HnMZTmBpY6CB.tsv >".\PVR\Dir 000\tmp\FRAEKeG1HnMZTmBpY6CB.tsv"
echo\EHuI3OiwSRGZWg7fsxsT.tsv >".\PVR\Dir 000\tmp\EHuI3OiwSRGZWg7fsxsT.tsv"

echo\NXGbTP1AlPxJGRPWaUJx.ts >".\PVR\Dir 001\NXGbTP1AlPxJGRPWaUJx.ts"
echo\Q2Eq97QpY7XQ7reWjUMi.ts >".\PVR\Dir 001\Q2Eq97QpY7XQ7reWjUMi.ts"
echo\UEAkSw76WV9j0494Lpvv.tsv >".\PVR\Dir 001\UEAkSw76WV9j0494Lpvv.tsv"
echo\IFBoWCY483HQE94fpCHU.tsv >".\PVR\Dir 001\IFBoWCY483HQE94fpCHU.tsv"

echo\HZH4jcvj2GvQzf7og5h3.ts >".\PVR\Dir 001\tmp\HZH4jcvj2GvQzf7og5h3.ts"
echo\EHRR1jKp3owr4lIsZZre.ts >".\PVR\Dir 001\tmp\EHRR1jKp3owr4lIsZZre.ts"
echo\1c0sB7o881uCGiYZUnvh.ts >".\PVR\Dir 001\tmp\1c0sB7o881uCGiYZUnvh.tsv"
echo\PnDUHnrCAGeUB3RRnwF5.tsv >".\PVR\Dir 001\tmp\PnDUHnrCAGeUB3RRnwF5.tsv"

echo\4nSfuQtqqOF6rPrs9TKb.tv >".\PVR\Dir 002\4nSfuQtqqOF6rPrs9TKb.ts"
echo\iNEIDXVdvKkN7abkFZJj.tv >".\PVR\Dir 002\iNEIDXVdvKkN7abkFZJj.ts"
echo\ygWGThdkefADZpMKWq30.tsv >".\PVR\Dir 002\ygWGThdkefADZpMKWq30.tsv"
echo\GLLcbLS8QZngJSDfM9k4.tsv >".\PVR\Dir 002\GLLcbLS8QZngJSDfM9k4.tsv"

echo\nqRuQhA9WrXvPk7i2ywt.ts >".\PVR\Dir 002\tmp\nqRuQhA9WrXvPk7i2ywt.ts"
echo\7b4hGoKaA9HxiSXtbpAT.ts >".\PVR\Dir 002\tmp\7b4hGoKaA9HxiSXtbpAT.ts"
echo\Y6PbfweT6aSgDiDDCVdU.tsv >".\PVR\Dir 002\tmp\Y6PbfweT6aSgDiDDCVdU.tsv"
echo\qvnIDtkY7uKtfcgStHzq.tsv >".\PVR\Dir 002\tmp\qvnIDtkY7uKtfcgStHzq.tsv"

echo\i1wW84pUm5TEGCWTueFw.ts >".\PVR\Dir 003\i1wW84pUm5TEGCWTueFw.ts"
echo\N7s3dLHI5QzdrkGZJJju.ts >".\PVR\Dir 003\N7s3dLHI5QzdrkGZJJju.ts"
echo\T1lQu7bcvmQepdh8iVzp.tsv >".\PVR\Dir 003\T1lQu7bcvmQepdh8iVzp.tsv"
echo\izNYHYHzFf4moJZPcOJv.tsv >".\PVR\Dir 003\izNYHYHzFf4moJZPcOJv.tsv"

echo\wnAVPzdos4RWjrJTt9cr.ts >".\PVR\Dir 003\tmp\wnAVPzdos4RWjrJTt9cr.ts"
echo\EXDlfbAqCyfB23l7ZZHz.ts >".\PVR\Dir 003\tmp\EXDlfbAqCyfB23l7ZZHz.ts"
echo\lgAduikvz4vlF1PWA892.tsv >".\PVR\Dir 003\tmp\lgAduikvz4vlF1PWA892.tsv"
echo\JcBmygrENpU4kEOOIFqP.tsv >".\PVR\Dir 003\tmp\JcBmygrENpU4kEOOIFqP.tsv"

:: # put a copy from outputs [tree]+[dir] into the clipboard and exit
  (dir /b /s /ad-h /o-d & %__AppDir__%tree.com /a /f . ) | %__AppDir__%clip.exe

endlocal & goto :eof


其他資源:

相關內容