Is there a way to call a shell in order to get a windows hard drive serial number?
If anybody has a code snippet, I’m sure there a load of people who would be interested…
Let’s try and not solve this by having to buy plugins
Sean
Is there a way to call a shell in order to get a windows hard drive serial number?
If anybody has a code snippet, I’m sure there a load of people who would be interested…
Let’s try and not solve this by having to buy plugins
Sean
I got some code here
but the definitions of objWMIService and colItems are missing - s is a string
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\\" & strComputer & "\\root\\CIMV2")
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_DiskDrive",,48)
For Each objItem in colItems
s=s+objItem.Caption+objItem.InterfaceType+objItem.SerialNumber
Next
Can’t you simply use the shell command to call wmic.exe and pass the “diskdrive get serialnumber” attributes?
how would that look?
ahh - I did it via terminal number … this is the serial for the diskdrive c: right?
however
dim sh as new shell
sh.execute "wmic:root:cli>diskdrive get serialnumber"
s=sh.result
got access denied
is that the right syntax?
I also tried
dim sh as new shell
sh.execute "-H -f wmic.exe "+chr(34)+" process get name,processid,commandline"+chr(34)
s=sh.result
without any luck as well
If you are after the serial number for a drive letter, assigned by Windows, rather than the physical disk serial, assigned by the manufacturer, then you can use the Windows API via declares…
[code]
function myGetFunctionSerial( strDrive as string ) as integer
// From: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
// Note (from the docs):…
// This function returns the volume serial number that the operating system assigns when a hard disk is formatted.
// To programmatically obtain the hard disk’s serial number that the manufacturer assigns,
// use the Windows Management Instrumentation (WMI) Win32_PhysicalMedia property SerialNumber.
// API call ( from docs )…
// BOOL WINAPI GetVolumeInformation(
// In_opt LPCTSTR lpRootPathName,
// Out_opt LPTSTR lpVolumeNameBuffer,
// In DWORD nVolumeNameSize,
// Out_opt LPDWORD lpVolumeSerialNumber,
// Out_opt LPDWORD lpMaximumComponentLength,
// Out_opt LPDWORD lpFileSystemFlags,
// Out_opt LPTSTR lpFileSystemNameBuffer,
// In DWORD nFileSystemNameSize
// );
// Note ( from docs ) for drive name…
// lpRootPathName [in, optional]
// A pointer to a string that contains the root directory of the volume to be described.
// If this parameter is NULL, the root of the current directory is used.
// A trailing backslash is required.
// For example, you specify \\MyServer\MyShare as “\\MyServer\MyShare”, or the C drive as “C:”.
soft declare function WinAPI_GetVolumeInformation _
lib “Kernel32.dll” _
alias “GetVolumeInformationW” ( _
byval lpRootPathName as WString, _
byval lpVolumeNameBuffer as WString, _
byval nVolumeNameSize as int32, _
byref lpVolumeSerialNumber as int32, _
byref lpFileSystemFlags as int32, _
byval lpFileSystemNameBuffer as WString, _
byval nFileSystemNameSize as int32 ) _
as int32
dim i32Result as int32
dim i32Serial as int32
dim i32Flags as int32
dim strDrivePath as string
if strDrive.len < 1 then RETURN ( 0 )
strDrivePath = strDrive
if strDrivePath.len < 2 then strDrivePath = strDrivePath + “:”
if strDrivePath.right(1) <> “” then strDrivePath = strDrivePath + “”
i32Result = WinAPI_GetVolumeInformation( strDrivePath,nil, 0, i32Serial, i32Flags, nil, 0 )
RETURN ( i32Serial )[/code]
Hi - thanks for the code … I am definitely after the physical number of the drive. People are more likely to change their OS than their hardware. So, a drive identity from windows would disable one of the main goals of my software - the idea that if they reformat their drive, change OS, the software and server would still recognize their computer.
wmi via command line should work if you want to avoid plugin.
Hi Christian - that’s exactly it… I’m just not sure how the command line would go
On Win.7…
On Win.XP i cannot find a `SerialNumber’ parameter
Help for the options is
Though I don’t see Serialnumber
mentioned on either XP or Win.7
There are more hoops to jump through to match \\.\PHYSICALDRIVEn to the drive letters of its disk partitions though
You can use a WinAPI call (check this http://msdn.microsoft.com/en-us/aa364993.aspx) for that, which will work for Windows XP and later.
Have you checked the Windows Functionality Suite? There is a chance the code you need is there already:
https://github.com/arbp/WFS
Also, the old forum is a very good source of information (I think the search engine here should also check the old forum since many of the questions that appear may be new here but are answered there):
http://forums.realsoftware.com/viewtopic.php?f=1&t=21380
http://forums.realsoftware.com/viewtopic.php?f=6&t=42855
Pixe
I got this code… however, it doesn’t return the same serialnumber I get when I open wmic and run
wmic:root\cli>diskdrive get serialnumber
My question is this… will the below code give some kind of physical information that won’t change when the harddrive is re-formatted and windows is re-installed?
Dim SerialNumber As String
Dim VolumeSerialNumber As Integer
Declare Function GetVolumeInformationA Lib "Kernel32" ( RootPathName as CString, VolumeNameBuffer as Ptr, VolumeNameSize as Integer, ByRef VolumeSerialNumber As Integer, MaximumComponentLength as Ptr, FileSystemFlags as Ptr, FileSystemNameBuffer as Ptr, FileSystemNameSize as Integer ) As Boolean
Dim Success As Boolean
Success = GetVolumeInformationA ( "C:\", Nil, 0, VolumeSerialNumber, Nil, Nil, Nil, 0 )
//If Not Success
SerialNumber = Hex( VolumeSerialNumber )
[quote=52445:@Sean Clancy]I got this code… however, it doesn’t return the same serialnumber I get when I open wmic and run
wmic:root\cli>diskdrive get serialnumber
My question is this… will the below code give some kind of physical information that won’t change when the harddrive is re-formatted and windows is re-installed?
Dim SerialNumber As String
Dim VolumeSerialNumber As Integer
Declare Function GetVolumeInformationA Lib "Kernel32" ( RootPathName as CString, VolumeNameBuffer as Ptr, VolumeNameSize as Integer, ByRef VolumeSerialNumber As Integer, MaximumComponentLength as Ptr, FileSystemFlags as Ptr, FileSystemNameBuffer as Ptr, FileSystemNameSize as Integer ) As Boolean
Dim Success As Boolean
Success = GetVolumeInformationA ( "C:\", Nil, 0, VolumeSerialNumber, Nil, Nil, Nil, 0 )
//If Not Success
SerialNumber = Hex( VolumeSerialNumber )
[/quote]
This is essentialy the same as my eariler example, which returns the Windows serial for a formatted drive, not the hardware serial
True, getVolumeInformation does not give the manufacturer’s serial number. This is from the MSDN corresponding to GetVolumeInformation: “This function returns the volume serial number that the operating system assigns when a hard disk is formatted.”
Sorry for the misleading information.
that’s ok - am I going to have to get a plugin for this?
You can use a .vbs via shell
http://forums.overclockers.com.au/showthread.php?t=983295
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\” & strComputer & “\root\cimv2”)
Set colBIOS = objWMIService.ExecQuery _
(“Select * from Win32_BIOS”)
For each objBIOS in colBIOS
Wscript.Echo "Manufacturer: " & objBIOS.Manufacturer
Wscript.Echo "Serial Number: " & objBIOS.SerialNumber
Next
Lennox
Isn’t the bios serial changeable?
Also, I just bought a MBS plugin from monkeybreadsoftware (Win) - but
a) it keeps saying “this serial number is too old for this plugin version. please update your license key”
b) No where in the documentation does it tell me how to get the physical hard drive serial number
even this is what Christian just told me I could do with this
c) It cost $69 USD
so, now I’m a little mad about this!
okay - my bad - it does do that (sorry Christian)
Not exactly correct. There are higher chance for the hard drive becomes defect before upgrading the OS. I would go for Bios Serial no.
Have a look at this URL: https://forum.xojo.com/4447-shell-issue/p1#p30972
(This will only works for Windows vista and upwards, as Windows XP Don’t support: ItemIndex(i) (obj = objs.ItemIndex(i))
If you want to use Hard drives Serial No. See link: http://library.wmifun.net/cimv2/win32_diskdrive.html and you can modify code above.