Home All Groups Group Topic Archive Search About

read disk serial number with .bat sript



Author
14 Sep 2007 4:36 PM
bvb47
hello!,

how can I read and assign the serial number of the hard drive or floppy to a
variable
in batch file?

thanks

Author
14 Sep 2007 5:46 PM
J Ford
With the aide of WMIC...

:/>wmic logicaldisk where drivetype=3 get name, freespace, systemname,
filesystem, size, volumeserialnumber

you can change the drivetype value:
0  Unknown
1  No Root Directory
2  Removable Disk
3  Local Disk
4  Network Drive
5  Compact Disc
6  RAM Disk

You can lookup win32_logicaldisk to get the other properties and methods



Show quote
"bvb47" wrote:

> hello!,
>
> how can I read and assign the serial number of the hard drive or floppy to a
> variable
> in batch file?
>
> thanks
>
>
Author
15 Sep 2007 9:46 AM
bvb47 via WinServerKB.com
Hello!, thanks

I can't use the wmic because the service is dissabled on my XP's network
(wmic logicaldisk where "deviceid='c:'" get volumeserialnumber)

I think that one easy way to know the serial number is doing someting like:

dir c: > file.txt
and now read the serial number from the file. But I don't know how can I do
this.
(read regular expression from file or from a pipe)

thanks

J Ford wrote:
Show quote
>With the aide of WMIC...
>
>:/>wmic logicaldisk where drivetype=3 get name, freespace, systemname,
>filesystem, size, volumeserialnumber
>
>you can change the drivetype value:
>0  Unknown
>1  No Root Directory
>2  Removable Disk
>3  Local Disk
>4  Network Drive
>5  Compact Disc
>6  RAM Disk
>
>You can lookup win32_logicaldisk to get the other properties and methods
>
>
>> hello!,
>>
>[quoted text clipped - 3 lines]
>>
>> thanks

Author
15 Sep 2007 5:34 PM
D.R.
@echo off
setlocal enabledelayedexpansion

fsutil fsinfo drives

set z_list=abcdefghijklmnopqrstuvwxyz

for /l %%a in (0,1,25) do (
  set z_drive=!z_list:~%%a,1!
  call :check-drive !z_drive!
)

echo+
echo S/N of C is:  !z_sn_c!

echo+
pause
exit /b


:check-drive
for /f "tokens=1,2,3" %%a in ('fsutil fsinfo drivetype %~1:\') do (
  if /i "%%c"=="fixed" call :getsn %~1
)
goto :eof


:getsn
for /f "tokens=1,2,3,4,5 skip=1" %%a in ('fsutil fsinfo volumeinfo %~1:\')
do (
  if /i "%%a %%b %%c"=="Volume Serial Number" (
    echo %~1:\  %%e
    set z_sn_%~1=%%e
  )
)
goto :eof
Author
15 Sep 2007 7:10 PM
bvb47 via WinServerKB.com
Great!,

thanks very much!, its what I was looking for.


D.R. wrote:
Show quote
>@echo off
>setlocal enabledelayedexpansion
>
>fsutil fsinfo drives
>
>set z_list=abcdefghijklmnopqrstuvwxyz
>
>for /l %%a in (0,1,25) do (
>  set z_drive=!z_list:~%%a,1!
>  call :check-drive !z_drive!
>)
>
>echo+
>echo S/N of C is:  !z_sn_c!
>
>echo+
>pause
>exit /b
>
>:check-drive
>for /f "tokens=1,2,3" %%a in ('fsutil fsinfo drivetype %~1:\') do (
>  if /i "%%c"=="fixed" call :getsn %~1
>)
>goto :eof
>
>:getsn
>for /f "tokens=1,2,3,4,5 skip=1" %%a in ('fsutil fsinfo volumeinfo %~1:\')
>do (
>  if /i "%%a %%b %%c"=="Volume Serial Number" (
>    echo %~1:\  %%e
>    set z_sn_%~1=%%e
>  )
>)
>goto :eof

--
Message posted via http://www.winserverkb.com

AddThis Social Bookmark Button