Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with ManagementObject
Message
De
24/08/2010 12:10:37
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Problem with ManagementObject
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01478159
Message ID:
01478159
Vues:
90
Anyone would know why the loManagementObject("QuotasDisabled").ToString() line doesn't work in a Windows Service mode?
        ' 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

            ' Reset the values
            cVolumeName = ""
            cVolumeSerialNumber = ""
            nFreeSpace = 0

            ' Adjust SQL as per type of drive
            Select Case nType

                ' Local drive
                Case 1
                    lcSQL = "SELECT FreeSpace,QuotasDisabled,VolumeName,VolumeSerialNumber " + _
                     "FROM Win32_LogicalDisk WHERE DeviceID=""" + cProviderName + """"

                    ' UNC drive
                Case 2
                    lcSQL = "SELECT FreeSpace,QuotasDisabled,VolumeName,VolumeSerialNumber " + _
                     "FROM Win32_LogicalDisk WHERE ProviderName=""" + cProviderName + """"

            End Select

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

            For Each loManagementObject In loSearcher.Get()

                ' In Windows Service, this doesn't work
                Try

                    ' Free disk space is irrelevant if per user quota's are enabled
                    If loManagementObject("QuotasDisabled").ToString() <> "true" Then
                        cVolumeName = loManagementObject("VolumeName")
                        nFreeSpace = loManagementObject("Freespace")
                        llSuccess = True
                    End If

                Catch loError As Exception

                End Try

                llSuccess = True
                cVolumeSerialNumber = loManagementObject("VolumeSerialNumber")
            Next

            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
Répondre
Fil
Voir

Click here to load this message in the networking platform