How do I convert a path with a drive letter to a UNC path

旧巷老猫 提交于 2020-01-01 08:22:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!