문제

Im writing a batch script to run on a flash drive. I need to validate the volume serial number of flash drive inside the code, therefore nobody should be able to run it from a different location.

Does anyone know how to validate serial number inside a batch file?

Example:

IF %VOL%==ABCD GOTO A ELSE EXIT
도움이 되었습니까?

해결책

Although there are several different ways to achieve the same thing, the original DOS/Windows command intended to manage volumes and serial numbers is VOL:

@echo off
for /F "skip=1 tokens=5" %%a in ('vol %~D0') do set Serial=%%a
if %Serial% equ ABCD-EF01 do (
    echo Valid serial number!
)

다른 팁

You can probably use WMIC and do something like:

wmic logicaldisk where drivetype=3 get volumeserialnumber

See parameter types in the link mentioned.

Edit:

@echo off
for /F "skip=1 delims=" %%j in ("wmic logicaldisk where deviceid = 'C:' get volumeserialnumber") do (
  set SERIAL=%%j
  goto :DONE
)
:DONE
echo  SERIAL=%SERIAL%

if "%SERIAL%"=="BLAH" (
   echo "Bluh"
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top