Reputation: 6376
From the command line, one can call net use without any parameters and obtain a list of computer connections on the local computer. This provides a listing of mapped network drives, as well as network connections to local network shares and web folders that were defined using the net use
command.
One can create a network connection to a local network share as follows:
net use \\MyComputerName\MyShareName
One can create a network connection to a web folder (e.g. WebDAV or SharePoint) as follows:
net use http://MySharePoint:12345/Shared%20Documents/MyFolder
Calling net use
will list the connections as follows:
C:\>net use
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
Unavailable Q: \\OldServer\OldShare Microsoft Windows Network
OK U: \\MyServerName\Name of Shared Folder
Microsoft Windows Network
Unavailable W: http://MyOldSharePoint Web Client Network
X: \\MyWebDavServer@12345\DavWWWRoot
Web Client Network
\\MySharePoint@12345\Shared%20Documents\MyFolder
Web Client Network
OK \\MyComputerName\MyShareName
Microsoft Windows Network
OK \\HostName\ShareName Microsoft Windows Network
The command completed successfully.
Mapped Network Drives
I am able to obtain the mapped drives in C# by calling DriveInfo.GetDrives()
.
Net Use Connections to Network Shares
I am able to obtain the connections to network shares that I created through PInvoke and the use of the Windows API NetUseEnum
.
Net Use Connections to Web Folders
I was able to obtain a listing of the Web Client Network servers through the use of the Windows APIs WNetOpenEnum
and WNetEnumResource
, however this does not get me the full path through to the share name and folders; it only gets me the server name.
I have not been able to find a way to obtain the Web Client Network connections to web folders that net use
allows you to define.
I am sure there must be a Windows API that can return these. If anyone knows, please advise. I certainly would like to avoid having to use a poor man's solution, such as calling net use
via a command line process and parse its output.
Note: I do not want a solution that uses WMI.
Upvotes: 1
Views: 981
Reputation: 2405
I'm fairly sure the Win32_LogicalDisk class should contain the info you need, if not try the registry, examples for both methods are in the Get-or-List-Network-shares-in-CSharp-using-WMI article
links
https://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx
http://www.morgantechspace.com/2014/02/Get-or-List-Network-shares-in-CSharp-using-WMI.html
Upvotes: 0