Jump to content
Sign in to follow this  
janama

DriveGetSerial

Recommended Posts

janama

Hi,

Ive been racking my brain all day over this,

DriveGetSerial Function/Method from AutoIt (not x) is the only language that returns my Kingston USB drive serials. (Well Done :shocked:

However i need to incorperate this into .net (c# or VB) and as this method is not available in AutoItX (i beleive?) im stuck

Ive tried a hundred (googled) VB and C# examples and they all return my HDD drives serials but not my Kingston USB drives' ? They show up as NUll, but not in AutoIt :( AU3 shows the actual firmware read only serial (not windows allocated / formatted one) of my Kingstons USB Drives

What magic did you use to accomplish this? lol

Anyone know of anyway i can incorporate this (great) feature into my .net app?

Pretty newbie-ish to .net so thir may be a way around this ? Would it be hard to incorporate

Regards to all

Share this post


Link to post
Share on other sites
autosc

Hi,

Ive been racking my brain all day over this,

DriveGetSerial Function/Method from AutoIt (not x) is the only language that returns my Kingston USB drive serials. (Well Done :shocked:

However i need to incorperate this into .net (c# or VB) and as this method is not available in AutoItX (i beleive?) im stuck

Ive tried a hundred (googled) VB and C# examples and they all return my HDD drives serials but not my Kingston USB drives' ? They show up as NUll, but not in AutoIt :( AU3 shows the actual firmware read only serial (not windows allocated / formatted one) of my Kingstons USB Drives

What magic did you use to accomplish this? lol

Anyone know of anyway i can incorporate this (great) feature into my .net app?

Pretty newbie-ish to .net so thir may be a way around this ? Would it be hard to incorporate

Regards to all

this might work in visual basic .NET ...

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

    Public Class MyWMIQuery

        Public Overloads Shared Function Main() As Integer

            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_LogicalDisk") 

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_LogicalDisk instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("VolumeSerialNumber: {0}", queryObj("VolumeSerialNumber"))
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function
    End Class
End Namespace

Share this post


Link to post
Share on other sites
janama

Hi, autosc

Thanks for reply

"SELECT * FROM Win32_LogicalDisk")

This does return serial for my USB Kingston but i think is the windows allocated (writable) one not the manufacturers readonly one

in autoit i can get like

; d: drive is my kingston usb
$seriel = DriveGetSerial("d:\")
MsgBox (4096,"Drive", $seriel)

By change-ing or adding the follwing to your vb code (query the Win32_PhysicalMedia instead of Win32_LogicalDisk) i do get the hardware serials of my other drives , but unlike AutoIt's 'DriveGetSerial' it doesnt return my Kingstons USB drive serial?

Console.WriteLine("start_Win32_PhysicalMedia")
        Try
            Dim searcher As New ManagementObjectSearcher( _
                "root\CIMV2", _
                "SELECT * FROM Win32_PhysicalMedia")

            For Each queryObj As ManagementObject In searcher.Get()
                'If Not queryObj("VolumeName") = "" Then

                Console.WriteLine("-----------------------------------")
                Console.WriteLine("Win32_PhysicalMedia instance")
                Console.WriteLine("-----------------------------------")
                Console.WriteLine("SerialNumber: {0}", queryObj("SerialNumber"))
                Console.WriteLine("-----------------------------------")
                Console.WriteLine("Name: {0}", queryObj("Name"))
                'End If
            Next
        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        End Try
        Console.WriteLine("Finish_Win32_PhysicalMedia")
        Console.ReadLine()

Thanks for having a go at this

Im still stuck :shocked:

Regards

Share this post


Link to post
Share on other sites
janama

Oops

Cancel all my ramblings above :shocked: it appears that after formatting AutoIt doesnt return physical serial after all (it returns the logical one, same as most source code floating around the net)

The reason the above code ( physical disks does not return the Hardware Vendors - readonly serial) is that its not compulsary with USB storage devices to have one in their firmware (unlike with HDD's which have to have one) And 5 around my place dont!

So i guess 2 solutions (if you need to keep track of your business/home usb stoarge device serials) is to

1. Not allow them to format these devices and use the logical serials instead

2. Only allow/provide devices that have a hardware serial embedded

Regards

Share this post


Link to post
Share on other sites
autosc

Oops

Cancel all my ramblings above :shocked: it appears that after formatting AutoIt doesnt return physical serial after all (it returns the logical one, same as most source code floating around the net)

The reason the above code ( physical disks does not return the Hardware Vendors - readonly serial) is that its not compulsary with USB storage devices to have one in their firmware (unlike with HDD's which have to have one) And 5 around my place dont!

So i guess 2 solutions (if you need to keep track of your business/home usb stoarge device serials) is to

1. Not allow them to format these devices and use the logical serials instead

2. Only allow/provide devices that have a hardware serial embedded

Regards

from your alternatives this works better ... I guess

1. Not allow them to format these devices and use the logical serials instead

Good Luck !

Share this post


Link to post
Share on other sites
giogio

i can get wath you ask in this way:

let me know

$wbemFlagReturnImmediately = 0x10

$wbemFlagForwardOnly = 0x20

$colItems = ""

$strComputer = "localhost"

$Output=""

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then

For $objItem In $colItems

if $objItem.InterfaceType = "usb" and $objItem.MediaType ="Removable media other than floppy" then

$Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF

endif

Next

;ConsoleWrite($Output)

Msgbox(1,"WMI Output",$Output)

;FileWrite(@TempDir & "\Win32_DiskDrive.TXT", $Output )

; Run(@Comspec & " /c start " & @TempDir & "\Win32_DiskDrive.TXT" )

Else

Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_DiskDrive" )

Endif

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.