Jump to content
Sign in to follow this  
legend

get serial from cmd

Recommended Posts

legend

HI :) is there a way I can get the serial from cmd to a variable?

if you go to cmd and type: vol

you get the serial number for (c:\)

C:\Users\mac>vol

Volume in drive C has no label.

Volume Serial Number is E497-2EDC

I want to make a hwid authentication system, however I am not sure that this number is changed, if you reinstall.

  • Like 1

Share this post


Link to post
Share on other sites
water

I suggest to use function DriveGetSerial. That's much easier.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Danyfirex

something like this:

#include <Constants.au3>

Vol()
Func Vol()
$output_read = Run(@ComSpec & " /c vol", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
$output = ""
While 1
$line = StdoutRead($output_read)
If @error Then ExitLoop
If StringLen($line) > 2 Then
$output &= $line
EndIf
WEnd
Local $aREResult = StringSplit($output,":")
msgbox(0,"Volume Serial Number is:",$aREResult[2])
EndFunc

regards

Edited by Danyfirex

Share this post


Link to post
Share on other sites
kylomas

legend,

You may also be interested in this thread which discusses various HD signatures, what they affect and how they are generated.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
W4RD14L3R

Got to agree with Water on this one.. DriveGetSerial seems much simpler

$Serial = DriveGetSerial( 'C:' )

Share this post


Link to post
Share on other sites
Kerros

There is a problem with DriveGetSerial, always has been that this function will return the Windows serial number, not a drive hardware serial number.

from the Help doc.

Remarks

The value returned is not the hardware serial number as found on the label of the drive, it is the Windows Volume ID for the drive.

The way to get the hardware serial number from Windows Vista on is through the WMI. (This does not work with windows XP)

$objWMIService = ObjGet("winmgmts:LocalHostrootCIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", 0x10 + 0x20)


If IsObj($colItems) Then
For $objItem In $colItems
Serial = $objItem.SerialNumber&@CRLF
next
EndIf

ConsoleWrite('Serial: '&$Serial&@CRLF)
Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
W4RD14L3R

You could always do it the long yet effective way of "Vol" works in the cmd for you then try outputting the display

text for cmd.exe

C:Usersmac> vol > C:vol.txt

This would output the drive id and serial number to C:vol.txt afterwards use the following code.

#Include <File.au3>
Local $File = 'C:Vol.txt'
For $n = 1 To _FileCountLines( $File ) Step + 1
$Line = FileReadLine( $File, $n )
If StringinStr( $Line, 'Volume Serial Number is' ) Then
  $Line = StringReplace( $Line, 'Volume Serial Number is', '' )
  $Line = StringReplace( $Line, ' ', '' )
  $DriveID = $Line
EndIf
Next

The code checks the lines in the file for Volume Serial.... Removes it and all blank whitespaces and leaves the code in the variable $DriveID

  • Like 1

Share this post


Link to post
Share on other sites
water

Kerros,

that's correct but the OP uses the VOL command. And VOL returns the volume serial number like DriveGetSerial does.

So DriveGetSerial seems to solve his problem.

To get the hardware serial number please search the forum. There was a discussion about this subject today.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
W4RD14L3R

You can also try the Unique Disk ID #

To get this you still need to go through cmd calls.

C:UsersGh0st> diskpart
diskpart> List Disk
          Disk 0     Online
diskpart> Select Disk 0
          Disk 0 selected
diskpart> UniqueID Disk
          Disk ID: xxxxxxx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×