pinvoke.net のNetDfsGetInfoの例を使用しています。DFS ターゲットのアクティブな unc パスを検索します。2 つのターゲットを持つ DFS パスでサブ DFSInfo を呼び出すと、両方のターゲットがアクティブであることが返されます。私はインターネットを検索し、ServerName と ShareName を呼び出すための vbNull を vbNullString に置き換える提案を見つけましたが、これは違いはありません。
誰かが私が間違っていることを説明できますか? 私が使用しているコードは次のとおりです。
Option Explicit On
'Option Strict On
Imports System
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Module modDFS
Declare Unicode Function NetDfsGetInfo Lib "NETAPI32.DLL" ( _
ByVal DfsEntryPath As String, _
ByVal ServerName As String, _
ByVal ShareName As String, _
ByVal Level As Integer, _
ByRef Buffer As IntPtr) As Integer
Declare Unicode Function NetApiBufferFree Lib "netapi32.dll" _
(ByVal buffer As IntPtr) As Long
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure _DFS_INFO_3
<MarshalAs(UnmanagedType.LPWStr)> Public EntryPath As String
<MarshalAs(UnmanagedType.LPWStr)> Public Comment As String
Public State As Int32
Public NumberOfStorages As Int32
Public storage As Int32
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure _DFS_STORAGE_INFO
Public State As Integer
<MarshalAs(UnmanagedType.LPWStr)> Public ServerName As String
<MarshalAs(UnmanagedType.LPWStr)> Public ShareName As String
End Structure
Public Sub DFSInfo(ByVal DfsEntryPath)
Dim DfsInfo3 As New _DFS_INFO_3
Dim DfsStorageInfo As New _DFS_STORAGE_INFO
Dim err_code As Integer
Dim bufPtf As IntPtr
Dim bufPtf2 As IntPtr
err_code = NetDfsGetInfo(DfsEntryPath, vbNullString, vbNullString, 3, bufPtf)
DfsInfo3 = CType(Marshal.PtrToStructure(bufPtf, GetType(_DFS_INFO_3)), _DFS_INFO_3)
bufPtf2 = DfsInfo3.storage
For i As Integer = 0 To DfsInfo3.NumberOfStorages - 1
'Increment the buffer and re-cast for each server in the list
DfsStorageInfo = CType(Marshal.PtrToStructure(bufPtf2, GetType(_DFS_STORAGE_INFO)), _DFS_STORAGE_INFO)
DfsInfo3.storage += Marshal.SizeOf(DfsStorageInfo)
bufPtf2 = DfsInfo3.storage
Debug.Print("\\" & DfsStorageInfo.ServerName & "\" & DfsStorageInfo.ShareName & " : " & DfsStorageInfo.State)
Next
NetApiBufferFree(bufPtf)
End Sub
End Module