Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Code does not execute on Windows Service
Message
De
19/09/2010 18:21:02
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Code does not execute on Windows Service
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01481890
Message ID:
01481890
Vues:
73
I have this method which collects some data about the drive:
        ' 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
Basically, I just found out that loManagementObject("VolumeSerialNumber") won't work in Windows Service when the service is started by Windows. I am just trying to know why this is not authorized. Also, this means I would have to scrap that entire code and replace that with something else.

Any comment on that situation?
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