Page 1 of 1

Physical serial number of hard disk Windows installed on that

Posted: 06 Sep 2017 13:34
by r2du-soft
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...

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

Posted: 06 Sep 2017 14:05
by Squashman
Where you been for three years?

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

Posted: 06 Sep 2017 14:34
by aGerman
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

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

Posted: 06 Sep 2017 14:59
by r2du-soft
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

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

Posted: 06 Sep 2017 15:12
by aGerman
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

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

Posted: 06 Sep 2017 15:26
by r2du-soft
this show me

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


windows 10 x64

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

Posted: 06 Sep 2017 15:32
by aGerman
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

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

Posted: 06 Sep 2017 15:50
by r2du-soft
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>

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

Posted: 06 Sep 2017 16:01
by aGerman
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

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

Posted: 06 Sep 2017 16:05
by r2du-soft

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!!!

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

Posted: 06 Sep 2017 16:11
by aGerman
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

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

Posted: 06 Sep 2017 16:22
by r2du-soft

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 !!!!!

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

Posted: 06 Sep 2017 16:25
by aGerman
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

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

Posted: 06 Sep 2017 18:09
by Squashman
Squashman wrote:Where you been for three years?

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

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

Posted: 07 Sep 2017 04:04
by r2du-soft
Thank you so much mr Steffen (aGerman) :wink:

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

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


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