Map network drive - NT (OS)

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
Basically i have done and success the coding how to map the drive with 2003 vb.net for Windows XP.

But, when I try on the Windows NT, the mapping drive is fail.

Is that possible the coding run for Win XP, and it will not run at Win NT?

Thanks advice.

or can have some coding is better!
 
finally i found that error ocurred at here : The window NT does not support the management scope. Here is my codes:
VB.NET:
Public Function GetDrive(ByVal DriveType As String, ByRef ErrMsg As String) As DataTable

        Dim dt As New DataTable, dr As DataRow
        Dim myScope As New ManagementScope("\\" & Environment.MachineName & "\root\cimv2")
        Dim oQuery As New SelectQuery("SELECT DeviceID, DriveType, ProviderName FROM win32_logicaldisk")
        Dim oResults As New ManagementObjectSearcher(myScope, oQuery)
        Dim oItem As ManagementObject
        Dim oProperty As PropertyData

        dt.Columns.Add("DriveLetter", GetType(String))
        dt.Columns.Add("Path", GetType(String))

        Try
            For Each oItem In oResults.Get()
                If oItem.Properties.Item("DriveType").Value.ToString = DriveType Then
                    dr = dt.NewRow()
                    'Local Drive
                    If DriveType = "3" Then
                        dr.Item("DriveLetter") = oItem.Properties.Item("DeviceID").Value.ToString & "\"
                    Else    'Network Drive
                        dr.Item("DriveLetter") = oItem.Properties.Item("DeviceID").Value.ToString
                        dr.Item("Path") = oItem.Properties.Item("ProviderName").Value.ToString
                    End If
                    dt.Rows.Add(dr)
                End If
            Next
        Catch ex As Exception
            ErrMsg = "* " & ex.Message
        Finally
            oResults.Dispose()
            oItem.Dispose()
            myScope = Nothing
            oQuery = Nothing
            oResults = Nothing
            oItem = Nothing
            oProperty = Nothing
        End Try

        Return dt

    End Function

Please help. Thanks! :)
 
Last edited:
Back
Top