Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the serial number of the drive
Message
De
19/09/2010 21:09:13
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Getting the serial number of the drive
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01481909
Message ID:
01481909
Vues:
103
I have the following two methods which return the serial number of a drive. The second one is an old approach. Both methods return a different serial number. Can anyone explain me what I get two different serial numbers?
        ' Get the information on a drive
        Public Function GetDriveInformation() As Boolean
            Dim lcSQL As String = ""
            Dim llSuccess As Boolean = False
            Dim loQuery As SelectQuery
            Dim loManagementObject As ManagementObject
            Dim loSearcher As ManagementObjectSearcher

            lcSQL = "SELECT FreeSpace,QuotasDisabled,VolumeName,VolumeSerialNumber " + _
             "FROM Win32_LogicalDisk WHERE DeviceID=""" + cProviderName + """"

            Try
                loQuery = New SelectQuery(lcSQL)
                loSearcher = New ManagementObjectSearcher(loQuery)

                For Each loManagementObject In loSearcher.Get()

                    ' Free disk space is irrelevant if per user quota's are enabled
                    If loManagementObject("QuotasDisabled").ToString() <> "true" Then
                        cVolumeSerialNumber = loManagementObject("VolumeSerialNumber")
                    End If

                Next

                llSuccess = True

            Catch loError As Exception
                cError = loError.Message
            End Try

            Return llSuccess
        End Function

        Public Function GetDriveSerialNumberWithFileSystemObject() As Boolean
            Dim llSuccess As Boolean = False
            Dim loDrive As Object = Nothing
            Dim loFileSystemObject As Object = Nothing

            Try

                ' Create a FileSystemObject object
                loFileSystemObject = CreateObject("Scripting.FileSystemObject")

                ' Assign the current drive letter if not specified
                loDrive = loFileSystemObject.GetDrive(cDrive)

                ' If the drive is ready
                If loDrive.IsReady Then
                    cVolumeSerialNumber = Math.Abs(loDrive.SerialNumber)
                    llSuccess = True
                Else
                    cError = cDriveNotReady
                End If

            Catch loError As Exception
                cError = loError.Message
            End Try

            Return llSuccess
        End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform