0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

チェックディスクなバッチファイル、和洋折衷案!!!?

Last updated at Posted at 2023-03-26

なんだかよくワカラン、チョーシにのりすぎたかも。
酔っ払いなんで許して。

chkdsk.cmd
@echo off
REM chcp 437
REM chcp 932
setlocal enableextensions enabledelayedexpansion
set cp=
(chcp |find "932" >nul 2>&1 && set cp=jp) || chcp |find "437" >nul 2>&1 || chcp 437
for /f "tokens=4,5 delims=. " %%A in ('ver') do set /a winver=%%A+%%B
:loop
if "%cp%"=="jp" (
    echo.
    echo 1. CHKDSK を読み取り専用モードで実行します。
    echo 2. ディスクのエラーを修復します。
    echo 3. 不良セクターを見つけて、読み取り可能な情報を回復します。
    echo 4. ヤメル^^!?
    echo.
    set /p opt="CHKDSK の実行方法を選択してください。[1,2,3,4]? "
    echo.
    if "!opt!"=="1" (
        set opt=
        goto :loop2
    )
    if "!opt!"=="2" (
        set opt=/F
        goto :loop2
    )
    if "!opt!"=="3" (
        set opt=/R
        goto :loop2
    )
    if not "!opt!"=="4" goto :loop
    goto :end
) else (
    echo.
    echo 1. Run CHKDSK in read-only mode.
    echo 2. Fixes errors on the disk.
    echo 3. Locates bad sectors and recovers readable information.
    echo 4. Abort^^!?
    echo.
    set /p opt="How to run CHKDSK [1,2,3,4]? "
    echo.
    if "!opt!"=="1" (
        set opt=
        goto :loop2
    )
    if "!opt!"=="2" (
        set opt=/F
        goto :loop2
    )
    if "!opt!"=="3" (
        set opt=/R
        goto :loop2
    )
    if not "!opt!"=="4" goto :loop
    goto :end
)

:loop2
if "%cp%"=="jp" (set /p drv="全ドライブをチェックしますか [Y,N]? ") else (set /p drv="Check all drives. [Y,N]? ")
echo.
if /i "%drv%"=="n" (
    if "%cp%"=="jp" (
        for %%A in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z) do (if exist %%A: vol %%A: |find "ボリューム ラベル")
    ) else (
        for %%A in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z) do (if exist %%A: vol %%A: |find "Volume in drive")
    )
    set drv=
    if "%cp%"=="jp" (
        echo.
        echo ドライブ文字を指定してください、複数でも構いません。
        echo.
        set /p drv=">"
    ) else (
        echo.
        echo Specifies the drive letter(s^).
        echo.
        set /p drv=">"
    )
    if not defined drv goto :loop2
    for %%A in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z) do set drv=!drv:%%A=%%A!
    set que=
    call :set_que
    goto :start_que_selected
)
if /i not "%drv%"=="y" goto :loop2

set que=C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z

:start_que
for %%A in (%que%) do (
    if exist %%A: (
        if %winver% geq 10 (
            if not defined opt call :wsh %%A
        )
        call :check_drv %%A
    )
)
goto :quit

:start_que_selected
for %%A in (%que%) do (
    if exist %%A: (
        if %winver% geq 10 (
            if not defined opt call :wsh %%A
        )
        call :check_drv %%A
    ) else (
        if "%cp%"=="jp" (
            echo.
            echo ドライブ %%A は見つかりません、ドライブ文字を確認してください。
            echo.
        ) else (
            echo.
            echo Drive %%A not found, check drive letter.
            echo.
        )
    )
)
goto :quit

:set_que
if not defined drv exit /b
set que=%que% %drv:~0,1%
set drv=%drv:~1%
goto :set_que

:wsh
set tempfile="%temp%\~%random%_getfs.vbs"
(
    echo Set fso=CreateObject("Scripting.FileSystemObject"^)
    echo fs=fso.GetDrive("%1"^).FileSystem
    echo fso.GetStandardStream(1^).Write(fs^)
    echo Set fso=Nothing
) >%tempfile%
start /wait /b cscript.exe %tempfile% |find "NTFS" >nul 2>&1
if errorlevel 1 set opt=/markclean
:del_temp
if exist %tempfile% del /f /a %tempfile%
if exist %tempfile% goto :del_temp
exit /b

:check_drv
echo on
chkdsk.exe %1: %opt%
@echo off
echo.
echo chkdsk.exe %1: %opt% finished.
echo.
pause
if "%opt%"=="/markclean" set opt=
exit /b

:end
exit
:quit
echo.
echo "%~f0"
echo.
pushd %SystemRoot%\system32
cmd.exe

修正しました、酔っぱらってるけど。

chkdsk.cmd
@if(0)==(0) echo off
REM Save as ANSI or SHIFT-JIS.
REM chcp 437 - us
REM chcp 932 - jp
::if exist %SystemRoot%\system32\wpeinit.exe wpeinit.exe
::Logs are piling up.
if exist %SystemRoot%\system32\wpeinit.exe (
    if not exist %SystemRoot%\system32\wpeinit.log (
        pushd %SystemRoot%\system32
        wpeinit.exe
        popd
    )
)
setlocal enableextensions enabledelayedexpansion
(chcp |find "932" >nul 2>&1 && set cp=jp) || (chcp |find "437" >nul 2>&1 || chcp 437)
for /f %%A in ('chkdsk.exe /? ^|find /i "/markclean"') do set markclean=%%A
:loop
cls
if defined cp (
    echo.
    echo 1. CHKDSK を読み取り専用モードで実行します []echo 2. ディスクのエラーを修復します [/F]echo 3. 不良セクターを見つけて、読み取り可能な情報を回復します [/R]echo 4. ヤメル^^!?
    echo.
    set q=
    set /p q="CHKDSK の実行方法を選択してください。[1,2,3,4]? "
    if "!q!"=="1" (
        set opt=
        goto :loop_jp
    )
    if "!q!"=="2" (
        set opt=/F
        goto :loop_jp
    )
    if "!q!"=="3" (
        set opt=/R
        goto :loop_jp
    )
    if "!q!"=="4" (
        goto :end
    ) else (
        goto :loop
    )
    :loop_jp
    echo.
    set q=
    set /p q="全ドライブをチェックしますか [Y,N]? "
    if /i "!q!"=="n" (
        call :get_labl
        echo.
        echo ドライブ文字を指定してください、複数でも構いません。
        echo.
        set drv=
        set /p drv=">> "
        if not defined drv goto :loop_jp
        call :set_cptl
        for %%A in (!que!) do (
            if exist %%A: (
                if defined markclean (
                    if not defined opt call :get_fs %%A
                )
                call :chk_drv %%A
            ) else (
                echo.
                echo ドライブ %%A は見つかりません、ドライブ文字を確認してください。
                echo.
                pause
            )
        )
        goto :quit
    )
    if /i not "!q!"=="y" goto :loop_jp
)
if not defined cp (
    echo.
    echo 1. Run CHKDSK in read-only mode [].
    echo 2. Fixes errors on the disk [/F].
    echo 3. Locates bad sectors and recovers readable information [/R].
    echo 4. Abort^^!?
    echo.
    set q=
    set /p q="How to run CHKDSK [1,2,3,4]? "
    if "!q!"=="1" (
        set opt=
        goto :loop_us
    )
    if "!q!"=="2" (
        set opt=/F
        goto :loop_us
    )
    if "!q!"=="3" (
        set opt=/R
        goto :loop_us
    )
    if "!q!"=="4" (
        goto :end
    ) else (
        goto :loop
    )
    :loop_us
    echo.
    set q=
    set /p q="Check all drives [Y,N]? "
    if /i "!q!"=="n" (
        call :get_labl
        echo.
        echo Specifies the drive letter(s^).
        echo.
        set drv=
        set /p drv=">> "
        if not defined drv goto :loop_us
        call :set_cptl
        for %%A in (!que!) do (
            if exist %%A: (
                if defined markclean (
                    if not defined opt call :get_fs %%A
                )
                call :chk_drv %%A
            ) else (
                echo.
                echo Drive %%A not found, check drive letter.
                echo.
                pause
            )
        )
        goto :quit
    )
    if /i not "!q!"=="y" goto :loop_us
)
:chk_all
set que=C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z
for %%A in (%que%) do (
    if exist %%A: (
        if defined markclean (
            if not defined opt call :get_fs %%A
        )
        call :chk_drv %%A
    )
)
goto :quit

:get_labl
echo.
for %%A in (C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z) do if exist %%A: (vol %%A: |find /i "ボリューム ラベル") || (vol %%A: |find /i "Volume in drive")
exit /b

:set_cptl
for %%A in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,S,T,U,V,W,X,Y,Z) do set "drv=!drv:%%A=%%A!"
:set_que
if not defined drv exit /b
set ^"que=%que%%drv:~0,1% ^"
set drv=%drv:~1%
goto :set_que

:get_fs
CScript.exe "%~f0" //E:JScript //Nologo %1 |find /i "NTFS" >nul 2>&1
if errorlevel 1 set opt=/markclean
exit /b

:chk_drv
echo on
chkdsk.exe %1: %opt%
@echo off
echo.
echo chkdsk.exe %1: %opt% finished.
echo.
pause
if "%opt%"=="/markclean" set opt=
exit /b

:quit
endlocal
echo.
echo "%~f0"
echo.
pushd %SystemRoot%\system32
cmd.exe
:end
exit
@end
var fso=WScript.CreateObject("Scripting.FileSystemObject")
var fs=fso.GetDrive(WScript.Arguments(0)).FileSystem
WScript.Echo(fs)
fs=null
fso=null

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?