Jump to content

get serial from cmd


 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...