1

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.

Elan
  • 6,084
  • 12
  • 64
  • 84

1 Answers1

0

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

fuzzybear
  • 2,325
  • 3
  • 23
  • 45
  • Registry is non-optimum. I would be interested an a Win32 API. Surely, I would expect that "net use" is calling some Windows API. – Elan Jan 23 '15 at 16:15
  • Theres a solution in the link that uses DirectoryEntry it uses ActiveDs com object – fuzzybear Jan 23 '15 at 20:29
  • I tried the sample code using the DirectoryEntry and it does not provide what I need. It returns for "localhost" all locally defined folder shares. That is not what I need. I can get these from the Windows API NetShareEnum. What I am looking for are the specific network connections to remote web folders per the examples I showed on the Web Client Network (configured through "net use"). – Elan Jan 23 '15 at 23:26
  • Think you may have what you need here also seems a dup on so http://stackoverflow.com/questions/8918477/how-can-i-enumerate-network-shares-and-web-folders-in-c http://www.codeproject.com/Articles/2939/Network-Shares-and-UNC-paths – fuzzybear Jan 24 '15 at 02:05
  • The duplicate you mention is a post I made 2 years ago. It is not exactly the same. At the time I was looking to browse through all types of folders and shares that were mapped network drives or configured as network locations. I have since resolved those requirements. The response given was a solution to enumerate local folder shares or WMI. Again, this particular question at hand is very specifically about **network connections to remote web folders established through "net use"**, not local folder shares, not Mapped Network Drives and not "Windows Network Locations". – Elan Jan 24 '15 at 03:56