Hi everyone,
As John Fauss mentioned you could accomplish this utilizing C#/ .Net and even PowerShell. Below are a couple of additional ways to obtain the serial number:
1) Using the Run() function and passing it the WMIC command; this is the less desirable way as it sends the output to a file which then has to be parsed but it can be done by using regular FileOpen etc. commands and parse what you need (I assume one knows how to do this so code not included). It would look as follows:
String ls_command
ls_command = 'cmd /c wmic diskdrive where "name like ' + "'%PHYSICALDRIVE0%'" + '" get name,SerialNumber > driveinfo.txt'
Run(ls_command)
2) The second way is preferred and is implemented using an OLEObject connecting to MSScriptControl.ScriptControl with VBScript...all inside PowerScript. It looks as follows:
//Declare necessary variables
OLEObject ole_wmi
Any la_DiskDrives[]
string ls_information
//Connect to OLEObject and build the function
ole_wmi = CREATE OLEObject
ole_wmi.ConnectToNewObject("MSScriptControl.ScriptControl")
ole_wmi.Language = "VBScript"
ole_wmi.AddCode('Function rtnDiskDrives()~r~n' &
+ 'DIM objDiskDrives(2)~r~n' &
+ 'strComputer = "."~r~n' &
+ 'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")~r~n' &
+ 'Set colItems = objWMIService.ExecQuery("SELECT name, SerialNumber FROM Win32_DiskDrive")~r~n' &
+ 'For Each objItem in colItems~r~n' &
+ 'If objItem.Name = "\\.\PHYSICALDRIVE0" Then ~r~n' &
+ 'objDiskDrives(0) = objItem.Name~r~n' &
+ 'objDiskDrives(1) = objItem.SerialNumber~r~n' &
+ 'End If~r~n' &
+ 'Next~r~n' &
+ 'rtnDiskDrives = objDiskDrives~r~n' &
+ 'End Function')
//Call the function
la_DiskDrives[] = ole_wmi.Eval("rtnDiskDrives")
ole_wmi.DisconnectObject()
DESTROY ole_wmi
//Present the information about the harddrive
ls_information = "Disk Drive: " + string(la_DiskDrives[1]) + "~r~n" + &
"Serial Number: " + string(la_DiskDrives[2]) + "~r~n"
MessageBox("Harddrive Information", ls_information)
In the above examples I'm assuming the drive required is Physical Drive 0 but it could be any drive on the system and both of the above approaches could be modified to include all drives.
I look forward to seeing your approach John and how you went about it, which OLEObject you used etc.
HTH.
Regards,
Mark