【问题标题】:How can I get the results of a CHKDSK that run on boot?如何获得在启动时运行的 CHKDSK 的结果?
【发布时间】:2016-07-21 12:47:19
【问题描述】:

有问题

CHKDSK 在我的机器重新启动时运行,并显示了一些内容。 问题是我不知道它显示了什么,因为它然后继续 完成后重新启动机器。如何让它停止, 暂停或以其他方式让我看看它做了什么?

chkdsk 无法运行,因为该卷正在被另一个进程使用意味着 ?, CHKDSK 需要独占访问它正在检查的磁盘 被指示尝试修复或修理。如果该磁盘是您的 Windows 驱动器 (C:),CHKDSK 不能独占访问,因为 Windows 只是使用该驱动器来运行您的系统。

当我们重新启动时,在加载 Windows 之前执行 CHKDSK。

CHKDSK 正常运行,完成后会重新启动系统 - 当然,这会导致屏幕上显示的任何进度或结果消失。

为了创建一个有用的工具来维护我的硬盘驱动器来检查、修复和修复它们的错误。

我做了这批

@echo off
Title Check Disk drives for errors and fix them by Hackoo 2016
mode con cols=67 lines=5 & Color 0A
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
set "TmpLog=%Tmp%\TmpLog.txt"
set "Log=%~dp0%computername%_%~n0.txt"
If Exist "%TmpLog%" Del "%TmpLog%"
If exist "%Log%" Del "%Log%"
REM  --> Check for permissions
Reg query "HKU\S-1-5-19\Environment" >nul 2>&1
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
Echo.
ECHO                        **************************************
ECHO                         Running Admin shell... Please wait...
ECHO                        **************************************

    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
::::::::::::::::::::::::::::
::          START         ::
::::::::::::::::::::::::::::
( Echo Scan started @ & Date /T & Time /T & echo ************************ ) > "%TmpLog%"
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=3" ^|find /i ":"') do (
    set "fix=%%i"
        Call :Affich !fix!
    (
        echo !fix! Drive 
        echo ************************
        echo(
        (echo O
        echo Y) | CHKDSK !fix! /f 
        echo(
        echo ************************
    )>> "%TmpLog%"
)
EndLocal
Goto Question
Exit /b

:Question
( echo Scan finished @ & Date /T & Time /T & echo ************************ )>> "%TmpLog%"
CMD /U /C Type "%TmpLog%" > "%Log%"
If Exist "%TmpLog%" Del "%TmpLog%"
(
    echo    Answ = MsgBox("Did you want to reboot the computer to complete the scanning ?",VbYesNo+VbQuestion,"Reboot the computer to check hard disk drives for errors by Hackoo"^)
    echo    If Answ = VbYes then 
    echo        wscript.Quit(0^)
    echo    Else
    echo        wscript.Quit(1^)
    echo    End If
)>"%tmp%\%~n0.vbs"

Cscript /nologo "%tmp%\%~n0.vbs"
IF "%errorlevel%" EQU "1" (start "" "%Log%" & Exit ) else (goto Shutdown)

:Shutdown 
echo(
cls
echo(
echo     Save your work - Reboot of your computer in 20 seconds
echo(
echo   Enregistrer vos documents - Redemarrage du PC dans 20 seconds 
Shutdown.exe /r /t 20 /c "Enregistrer vos documents - Redemarrage du PC dans 20 secondes"
start "" %Log%
pause>nul
exit /b

:Affich
Cls
echo(
echo                ***********************************
Echo                 Please wait a while Scanning "%~1"
echo                ***********************************
Timeout /T 2 /nobreak>nul
exit /b

所以,我的问题是:我怎样才能得到CHKDSK 的结果,它可以通过批处理或powershell 启动?

【问题讨论】:

  • 谁不赞成这个问题,告诉我为什么?
  • 不确定,但日志可能在系统的事件日志中...也许您会找到答案herehere...
  • 无论如何,为您的努力和您完成的一批出色的工作+1。是的,恕我直言,您的问题确实中肯。恭喜。
  • @statosdotcom 谢谢!为了您的支持和您的理解!并说我自己找到了这个问题的答案,见下文。当然,还要感谢 Ansgar Wiechers 为我的搜索指明了正确的方向,我将它分享给了社区!

标签: powershell batch-file


【解决方案1】:

信息是recorded in the eventlog。你应该可以像这样获得它(使用 PowerShell):

Get-EventLog -LogName Application -Source Wininit |
    Where-Object { $_.Message -like '*checking file system*' } |
    Sort-Object TimeGenerated -Descending |
    Select-Object -First 1 -Expand Message

【讨论】:

  • 感谢您的回复,这是一个好主意,我会努力解决这个问题,但我想知道为什么这个问题被否决了,我不明白为什么,这是一个不好的问题吗?在这种情况下我应该删除它吗?请我需要你的建议再次谢谢你!
  • 所有的反对票都不是我的,所以我只能推测原因,我不会这样做。
  • 我没有说反对意见来自你 :) 但我想知道当有人反对一个问题或答案时,如果我犯了 couse.just,为什么下次要避免同样的错误再次感谢您的帮助。我真的很感激!
【解决方案2】:

我找到了答案here

get-winevent -FilterHashTable @{logname="Application"; id="1001"}| ?{$_.providername –match "wininit"} | fl timecreated, message | out-file Desktop\CHKDSKResults.txt

在批处理文件中我们可以这样做:

@echo off
set "Log=%tmp%\CHKDSKResults.txt"
If Exist "%Log%" del "%Log%"
Powershell -Command "& "Get-winevent -FilterHashTable @{logname='Application'; id='1001'}^|?{$_.providername -match 'wininit'} ^| fl timecreated, message ^| out-file '%Log%'"
Start "" "%Log%"

编辑:2016 年 7 月 27 日最终代码:

@echo off
Title Check Disk drives for errors and fix them by Hackoo 2016
mode con cols=67 lines=5 & Color 0A
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
set "TmpLog=%Tmp%\TmpLog.txt"
set "Log=%~dp0%computername%_%~n0.txt"
set "MyVBSFile=%~dp0%~n0_On_Boot.vbs"
set "Value=CHKDSK_ON_BOOT"
Set "Key=HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
If Exist "%TmpLog%" Del "%TmpLog%"
If exist "%Log%" Del "%Log%"
REM  --> Check for permissions
Reg query "HKU\S-1-5-19\Environment" >nul 2>&1
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
Echo.
ECHO                        **************************************
ECHO                         Running Admin shell... Please wait...
ECHO                        **************************************

    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
::::::::::::::::::::::::::::
::          START         ::
::::::::::::::::::::::::::::
( Echo Scan started @ & Date /T & Time /T & echo ************************ ) > "%TmpLog%"
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=2" %%i in ('wmic logicaldisk where "drivetype=3" ^|find /i ":"') do (
    set "fix=%%i"
        Call :Affich !fix!
    (
        echo !fix! Drive 
        echo ************************
        echo(
        (echo O
        echo Y) | CHKDSK !fix! /f 
        echo(
        echo ************************
    )>> "%TmpLog%"
)
EndLocal
Goto Question
Exit /b
::******************************************************************
:Question
( echo Scan finished @ & Date /T & Time /T & echo ************************ )>> "%TmpLog%"
CMD /U /C Type "%TmpLog%" > "%Log%"
If Exist "%TmpLog%" Del "%TmpLog%"
(
    echo    Answ = MsgBox("Did you want to reboot the computer to complete the scanning ?",VbYesNo+VbQuestion,"Reboot the computer to check hard disk drives for errors by Hackoo"^)
    echo    If Answ = VbYes then 
    echo        wscript.Quit(0^)
    echo    Else
    echo        wscript.Quit(1^)
    echo    End If
)>"%tmp%\%~n0.vbs"

Cscript /nologo "%tmp%\%~n0.vbs"
IF "%errorlevel%" EQU "1" ( goto AddKey ) else ( goto Shutdown )
::******************************************************************
:Shutdown
echo(
cls
echo(
echo     Save your work - Reboot of your computer in 120 seconds
echo(
echo   Enregistrer vos documents - Redemarrage du PC dans 120 seconds 
Call:AddKey && Shutdown.exe /r /t 120 /c "Enregistrer vos documents - Redemarrage du PC dans 120 secondes"
pause>nul
exit /b
::******************************************************************
:Affich
Cls
echo(
echo                ***********************************
Echo                 Please wait a while Scanning "%~1"
echo                ***********************************
Timeout /T 2 /nobreak>nul
exit /b
::******************************************************************
:AddKey
reg query "%key%" /v "%Value%" >nul 2>&1
If "%errorlevel%" EQU "0" ( Goto :EOF
    ) Else (
    reg add "%Key%" /v "%Value%" /t REG_SZ /d "%MyVBSFile%">nul
    (
        echo Option Explicit
        echo 'Run as Admin
        echo If Not WScript.Arguments.Named.Exists("elevate"^) Then
        echo    CreateObject("Shell.Application"^).ShellExecute DblQuote(WScript.FullName^) _
        echo    , DblQuote(WScript.ScriptFullName^) ^& " /elevate", "", "runas", 1
        echo     WScript.Quit
        echo End If
        echo Dim ws,PSCommand,LogFile,ret
        echo LogFile = Left(Wscript.ScriptFullName,InstrRev(Wscript.ScriptFullName, "."^)^) ^& "txt"
        echo set ws = createobject("wscript.shell"^)
        echo PSCommand = "cmd /c Powershell -Command ""& ""Get-winevent -FilterHashTable @{logname='Application'; id='1001'}^|?{$_.providername -match 'wininit'} ^| fl timecreated, message ^| out-file "^& SimpleQuote(LogFile^) ^&""
        echo ret = ws.run(PScommand,0,True^)
        echo ws.run DblQuote(LogFile^)
        echo '**************************************
        echo Function DblQuote(Str^)
        echo    DblQuote = chr(34^) ^& Str ^& chr(34^)
        echo End function
        echo '**************************************
        echo Function SimpleQuote(Str^)
        echo    SimpleQuote = ChrW(39^) ^& Str ^& ChrW(39^)
        echo End Function
        echo '**************************************
    )>"%MyVBSFile%"
start "" "%Log%"
)   
Exit /b
::*******************************************************************

【讨论】:

    猜你喜欢
    • 2021-08-21
    • 2018-12-27
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 1970-01-01
    • 2012-09-24
    • 2020-10-13
    相关资源
    最近更新 更多