回复 2# Batcher - @echo off
- Setlocal EnableDelayedExpansion
- set "LOGFILE=%~dpn0.LOG"
-
- Echo !date:~0,10! !time! --START CreateSHA1>>"!LOGFILE!"
- certutil /? 1>nul 2>nul
- if errorlevel 1 goto :exit
- wmic /? 1>nul 2>nul
- if errorlevel 1 goto :exit
-
- For /r "D:\" %%a in (*.*) do (
- set fail=1
- echo %%a
- set "currentfilename=%%a"
- set "SIZE=%%~za"
- set "NXNAME=%%~nxa"
- Call :Process
- )
-
- Echo !date:~0,10! !time! --END CreateSHA1>>"!LOGFILE!"
-
- exit /b
- :Process
- Call :GetSHA1
- if fail==0 exit /b
- Call :GetVersion
- Call :CreateFile
-
- exit /b
- :GetSHA1
- set SHA1=
- set "InFile=!currentfilename!"
- For /F "skip=1 delims=" %%b in ('certutil -hashfile "!InFile!" SHA1') do (
- set "SHA1=%%b"
- if "!SHA1:~0,8!"=="CertUtil" Call :OutputLog GetSHA1 1 "!SHA1:CertUtil:=!" & exit /b
- set "SHA1=!SHA1: =!"
- ECHO SHA1:!SHA1!
- Exit /b
- )
-
- EXIT /B
- :GetVersion
- set filename=!currentfilename:\=\\!
- For /F "skip=1 delims=" %%c in ('wmic datafile where "name='!filename!'" get version') do (
- set "Version=%%c"
- if not "!Version:~0,1!"==" " (
- echo Ver:!Version!
- exit /b
- ) else (
- rem echo GetVersion Failed
- exit /b
- )
- )
-
- EXIT /B
- :CreateFile
- echo !NXNAME! Ver:!Version! SIZE:!SIZE! SHA1:!SHA1! >>%~dp0!NXNAME!.SHA1
- if not exist "%~dp0!NXNAME!.SHA1" Call :OutputLog CreateFile 1
- for %%z in ("%~dp0!NXNAME!.SHA1") do ( if %%~zz==0 Call :OutputLog CreateFile 1 "Invalid Data" & exit /b)
-
- exit /b
- :OutputLog
- set PARAMETERS=
- set PARAMETERS=%*
- if "!PARAMETERS!"=="" echo !date:~0,10! !time! --!currentfilename! OutputLog Failed No Parameters >>"!LOGFILE!" & exit /b
- if !errorlevel!==0 (
- set Fail=1
- if %1==Rename Echo !date:~0,10! !time! --!currentfilename! Rename to !filesrename! Succeeded>>"!LOGFILE!"
- if %1==Decompression Echo !date:~0,10! !time! --!currentfilename! Decompression Succeeded>>"!LOGFILE!"
- ) else (
- set Fail=0
- if %1==Rename Echo !date:~0,10! !time! --!currentfilename! Rename to !filesrename! Failed ErrorCode=!errorlevel!>>"!LOGFILE!"
- if %1==Decompression Echo !date:~0,10! !time! --!currentfilename! Decompression Failed ErrorCode=!errorlevel!>>"!LOGFILE!"
- )
- if "%2"=="0" (
- set Fail=1
- if %1==Getdate Echo !date:~0,10! !time! --!currentfilename! Get File Time Succeeded>>"!LOGFILE!"
- )
- if "%2"=="1" (
- set Fail=0
- if %1==Getdate Echo !date:~0,10! !time! --!currentfilename! Get File Time Failed %~3>>"!LOGFILE!"
- if %1==CreateFile Echo !date:~0,10! !time! --!currentfilename! CreateFile Failed %~3>>"!LOGFILE!"
- if %1==GetSHA1 Echo !date:~0,10! !time! --!currentfilename! GetSHA1 Failed %~3>>"!LOGFILE!"
- )
-
- exit /b
- :Exit
- echo Fatal error,try to change the platform,press any key to exit his program
- pause >nul
- exit /b
复制代码
|