问题
Is there a way to determine the protocol name (SMB/CIFS,NFS) and version that is used for a mounted network drive on windows? (in C#)
EDIT
Using info from Rusted's answer, i got the following information from a windows 7 computer on the network.
NETRESOURCE res = WinApiWNETwrapper.GetResourceInfo("\\Test-PC");
res.dwDisplayType = SERVER
res.dwScope = 0
res.dwType = ANY
res.dwUsage = CONTAINER
res.lpComment = ""
res.lpLocalName = null
res.lpProvider = "Microsoft Windows Network"
res.lpLocalName = "\\Test-PC"
NETINFOSTRUCT netinfo = WinApiWNETwrapper.GetNetworkInfo("\\Test-PC");
netinfo.cbStructureSize = 32
netinfo.dwCharacteristics = 0
netinfo.dwDrives = -1
netinfo.dwHandle = 1880621056
netinfo.dwPrinters = -1
netinfo.dwProviderVersion = 1024
netinfo.dwStatus = Running
netinfo.wNetType = LANMAN
SERVER_TRANSPORT_INFO_1[] transports = WinApiNETwrapper.ServerTransportEnum_1("\\Test-PC");
transports[0].svti1_domain = "WORKGROUP"
transports[0].svti1_networkaddress = "TEST-PC"
transports[0].svti1_numberofvcs = 0
transports[0].svti1_transportaddress = 73107336
transports[0].svti1_transportaddresslength = ...
transports[0].TransportAddress = "TEST-PC"
transports[0].svti1_transportname = "\\Device\\NetbiosSmb"
transports[1].svti1_transportname = "\\Device\\NetBT_Tcpip_{F4C75115-...}"
transports[2].svti1_transportname = "\\Device\\NetBT_Tcpip_{70BD9048-...}"
The important part seems to be:
transports[0].svti1_transportname = "\\Device\\NetbiosSmb"
But i cannot find the version number of the SMB protocol anywhere. Any ideas?
回答1:
I suppose you've need the Windows Networking (WNet) API, a value from NetType field in NETINFOSTRUCT returned by WNetGetNetworkInformation function.
Here is open-source project in C#, check files in WnetApi folder for .NET wrappers for Wnet API.
To get the UNC path for a mapped drive use PathToUNC method from this project.
来源:https://stackoverflow.com/questions/10800616/determine-protocol-of-a-network-drive