问题
How do I convert a path with a drive letter like W:\Path\Share
to the equivalent unc path like \\server\Share\File
in .Net?
At the command prompt you can run net use
and that will list the mappings. How do I get at that info in .Net?
回答1:
You can use P/Invoke and call on a native function such as WNetGetUniversalName.
回答2:
To get a list of the shared folders on the current machine in .NET you have to options:
- Querying the Win32_share WMI class using the classes in the System.Management namespace
- Invoking the NetShareEnum function in Win32 using P/Invoke
Note that the calling process will have run in the context of a user with administrative privileges for this to work.
回答3:
To answer your question about net use
here is a good solution
Get UNC Path for Mapped Drive VB.net
I like the net use
way.
来源:https://stackoverflow.com/questions/556649/how-do-i-convert-a-path-with-a-drive-letter-to-a-unc-path