Physical serial number of hard disk Windows installed on that

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Physical serial number of hard disk Windows installed on that

#1 Post by r2du-soft » 06 Sep 2017 13:34

how can get The hard disk where Windows is installed,And Windows is using that hard drive right away SERIAL NUMBER...

i use from

Code: Select all

wmic path win32_physicalmedia get SerialNumber


but show me all hard disks serial numbers also show me flash disk serial number....
WD-WCC4M1DCUPP1
WD-WMC4J0057355
0C7C01D66

my hard disk where Windows is installed on serial number is: WD-WMC4J0057355
if i don't know which serial is for which hard disk where Windows is installed how can find that?

i just want see hard disk where Windows is installed serial number...

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Physical serial number of hard disk Windows installed on that

#2 Post by Squashman » 06 Sep 2017 14:05

Where you been for three years?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Physical serial number of hard disk Windows installed on that

#3 Post by aGerman » 06 Sep 2017 14:34

WMIC is quite tricky :lol:
Just try if that gives the output you're after:

Code: Select all

@echo off &setlocal
for /f tokens^=2^ delims^=^" %%i in ('wmic path Win32_LogicalDiskToPartition get^|findstr "\"%SystemDrive%\""') do (
  for /f "tokens=2 delims=#," %%j in ("%%i") do (
      for /f %%k in ('wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE%%j'" get SerialNumber /value') do (
        for /f %%l in ("%%k") do set "%%l"
      )
  )
)
echo %SerialNumber%
pause

Steffen

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Physical serial number of hard disk Windows installed on that

#4 Post by r2du-soft » 06 Sep 2017 14:59

aGerman wrote:WMIC is quite tricky :lol:
Just try if that gives the output you're after:

Code: Select all

@echo off &setlocal
for /f tokens^=2^ delims^=^" %%i in ('wmic path Win32_LogicalDiskToPartition get^|findstr "\"%SystemDrive%\""') do (
  for /f "tokens=2 delims=#," %%j in ("%%i") do (
      for /f %%k in ('wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE%%j'" get SerialNumber /value') do (
        for /f %%l in ("%%k") do set "%%l"
      )
  )
)
echo %SerialNumber%
pause

Steffen


Show Message:
ECHO is off

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Physical serial number of hard disk Windows installed on that

#5 Post by aGerman » 06 Sep 2017 15:12

Okay then we have to search the failure (FWIW Works for me Win10 x86).

Code: Select all

@echo off &setlocal
for /f tokens^=2^ delims^=^" %%i in ('wmic path Win32_LogicalDiskToPartition get^|findstr "\"%SystemDrive%\""') do (
  echo i is %%i
  for /f "tokens=2 delims=#," %%j in ("%%i") do (
      echo j is %%j
      for /f %%k in ('wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE%%j'" get SerialNumber /value') do (
        for /f %%l in ("%%k") do set "%%l"
      )
  )
)
echo %SerialNumber%
pause

What do you get for i and j?

Steffen

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Physical serial number of hard disk Windows installed on that

#6 Post by r2du-soft » 06 Sep 2017 15:26

this show me

i is Disk #1, Partition #1
j is 1
ECHO is off.
Press any key to continue . . .


windows 10 x64

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Physical serial number of hard disk Windows installed on that

#7 Post by aGerman » 06 Sep 2017 15:32

Seems you get the right drive#. So Win32_PhysicalMedia is the culprit. Could you run

Code: Select all

wmic path Win32_PhysicalMedia get Tag /value

from within a cmd window.

Steffen

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Physical serial number of hard disk Windows installed on that

#8 Post by r2du-soft » 06 Sep 2017 15:50

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\RoseSoftware>wmic path Win32_PhysicalMedia get Tag /value


Tag=\\.\PHYSICALDRIVE0


Tag=\\.\PHYSICALDRIVE1


Tag=\\.\PHYSICALDRIVE2




C:\Users\RoseSoftware>

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Physical serial number of hard disk Windows installed on that

#9 Post by aGerman » 06 Sep 2017 16:01

That was expected :lol: Still don't see the failure.
What about

Code: Select all

wmic path Win32_PhysicalMedia get Tag,SerialNumber /value
and in case this worked

Code: Select all

wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE1'" get SerialNumber /value

Steffen

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Physical serial number of hard disk Windows installed on that

#10 Post by r2du-soft » 06 Sep 2017 16:05

Code: Select all

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\RoseSoftware>wmic path Win32_PhysicalMedia get Tag,SerialNumber /value


SerialNumber=     WD-WCC4M1DCUPP1
Tag=\\.\PHYSICALDRIVE0


SerialNumber=     WD-WMC4J0057355
Tag=\\.\PHYSICALDRIVE1


SerialNumber=0C7C01D66
Tag=\\.\PHYSICALDRIVE2




C:\Users\RoseSoftware>wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE1'" get SerialNumber /value


SerialNumber=     WD-WMC4J0057355




C:\Users\RoseSoftware>



yes in command line thats worked but in batch file not show me serial number!!!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Physical serial number of hard disk Windows installed on that

#11 Post by aGerman » 06 Sep 2017 16:11

That's annoying :(
Does this work (without trying to catch the value in another FOR /F loop)?

Code: Select all

@echo off &setlocal
for /f tokens^=2^ delims^=^" %%i in ('wmic path Win32_LogicalDiskToPartition get^|findstr "\"%SystemDrive%\""') do (
  for /f "tokens=2 delims=#," %%j in ("%%i") do (
      wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE%%j'" get SerialNumber /value
  )
)
pause

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Physical serial number of hard disk Windows installed on that

#12 Post by r2du-soft » 06 Sep 2017 16:22

Code: Select all


SerialNumber=     WD-WMC4J0057355



Press any key to continue . . .





:D worked
thank you Steffen

Already I for /f had problems
The problem was already that: echo not show when i use from for /f !!!!!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Physical serial number of hard disk Windows installed on that

#13 Post by aGerman » 06 Sep 2017 16:25

Got it. There are spaces between equal sign and the value in your output.
If you need the value to be assigned to a variable:

Code: Select all

@echo off &setlocal
for /f tokens^=2^ delims^=^" %%i in ('wmic path Win32_LogicalDiskToPartition get^|findstr "\"%SystemDrive%\""') do (
  for /f "tokens=2 delims=#," %%j in ("%%i") do (
      for /f "tokens=2 delims== " %%k in ('wmic path Win32_PhysicalMedia where "Tag='\\\\.\\PHYSICALDRIVE%%j'" get SerialNumber /value') do (
        for /f "delims=" %%l in ("%%k") do set "SerialNumber=%%l"
      )
  )
)
echo %SerialNumber%
pause

Steffen

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Physical serial number of hard disk Windows installed on that

#14 Post by Squashman » 06 Sep 2017 18:09

Squashman wrote:Where you been for three years?

کجا بودی به مدت سه سال

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: Physical serial number of hard disk Windows installed on that

#15 Post by r2du-soft » 07 Sep 2017 04:04

Thank you so much mr Steffen (aGerman) :wink:

Squashman wrote:
Squashman wrote:Where you been for three years?

کجا بودی به مدت سه سال


Resting
استراحت می کردم
:D

Post Reply