Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cannot used DriveInfo() on UNC drive
Message
De
02/11/2006 02:17:46
 
 
À
01/11/2006 18:19:36
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01166071
Message ID:
01166514
Vues:
15
>Strange. Might be my bad VB coding. I tried it here and got correct information from all remote UNC paths. C# version worked better. It might be that VB version is not handling return values right (PULARGE_INTEGER).

Could you try this class as is:
Imports System.Management
Imports System.Runtime.InteropServices

Namespace Framework

    Public Class DriveInformation

        Public cError As String = ""
        Public cProviderName As String = ""
        Public cVolumeName As String = ""
        Public nAvailableByte As Double = 0
        Public nFreeSpace As Double = 0
        Public nFreeSpaceToCaller As Double = 0

        ' Type of drive
        ' 1 Local drive
        ' 2 UNC drive
        Public nType As Integer = 1

        Private oApp As Framework.App
        Private oProcess As Framework.LXProcess

        Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
         (ByVal lpRootPathName As String, _
          ByRef lpFreeBytesAvailableToCaller As Double, _
          ByRef lpTotalNumberOfBytes As Double, _
          ByRef lpTotalNumberOfFreeBytes As Double) As Integer

        ' This is when we access the data provider in desktop and Web service mode
        Sub New(ByVal toApplication As Framework.App)
            oApp = toApplication
        End Sub

        ' This is when we access the data provider in a Web mode
        Public Sub New(ByVal toProcess As Framework.LXProcess)
            oProcess = toProcess
            oApp = oProcess.oApp
        End Sub

        ' Get the information on a drive
        Public Function GetFreeSpace() As Boolean
            Dim lcSQL As String = ""
            Dim llSuccess As Boolean = False
            Dim loQuery As SelectQuery
            Dim loManagementObject As ManagementObject
            Dim loSearcher As ManagementObjectSearcher

            ' Adjust SQL as per type of drive
            Select Case nType

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

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

            End Select

            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
                    cVolumeName = loManagementObject("VolumeName")
                    nFreeSpace = loManagementObject("Freespace")
                    llSuccess = True
                End If

            Next
            Return llSuccess
        End Function

        ' Get the information on a drive
        Public Function GetFreeSpaceInteropServices() As Boolean
            GetDiskFreeSpaceEx(cProviderName, nFreeSpaceToCaller, nAvailableByte, nFreeSpace)
            Return True
        End Function

    End Class

End Namespace
And, call it like that:
        Dim loDriveInformation As Framework.Framework.DriveInformation = New Framework.Framework.DriveInformation(oProcess)

            loDriveInformation.cProviderName = "\\1.1.1.1\D$"

            If loDriveInformation.GetFreeSpaceInteropServices() Then
                Throw New System.Exception(loDriveInformation.cVolumeName + " " + loDriveInformation.nFreeSpace.ToString + _
                 loDriveInformation.nAvailableByte.ToString + " " + loDriveInformation.nFreeSpaceToCaller.ToString)
            Else
                Throw New System.Exception("not working")
            End If
You will have to adjust the calling code to represent your UNC remote path as well as the declaration. Then, you may let me know if from that code as is if you are able to get the drive information from a UNC remote path from VB.NET.
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform