将Windows驱动器号解析为路径(替代和网络) [英] Resolve Windows drive letter to a path (subst and network)

查看:154
本文介绍了将Windows驱动器号解析为路径(替代和网络)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否存在使用驱动器号(例如X:\foo\bar.txt)将路径解析为等效的UNC路径的通用方法,该路径可能是以下之一:

I wonder if there is a universal way of resolving a path using a drive letter (such as X:\foo\bar.txt) into its equivalent UNC path, which might be one of the following:

  • X:\foo\bar.txt,如果X:是真实驱动器(即硬盘,USB记忆棒等)
  • \\server\share\foo\bar.txt(如果X:是安装在\\server\share
  • 上的网络驱动器)
  • C:\xyz\foo\bar.txt如果X:SUBST命令将X:映射到C:\xyz
  • 的结果
  • X:\foo\bar.txt if X: is a real drive (i.e. hard disk, USB stick, etc.)
  • \\server\share\foo\bar.txt if X: is a network drive mounted on \\server\share
  • C:\xyz\foo\bar.txt if X: is the result of a SUBST command mapping X: to C:\xyz

我知道有部分解决方案,将:

I know that there are partial solutions which will:

  1. 解析网络驱动器(例如,参见解析SUBST驱动器盘符(请参阅QueryDosDevice,该驱动器盘符按预期工作,但不会为诸如本地驱动器或网络驱动器之类的东西返回UNC路径).

    Resolve the SUBST drive letter (see QueryDosDevice which works as expected, but does not return UNC paths for things such as local drives or network drives).

    我是否缺少在Win32中实现此驱动器号解析的简单方法?还是我真的必须把WNetGetUniversalNameQueryDosDevice弄混才能得到我需要的东西?

    Am I missing some straightforward way of implementing this drive letter resolution in Win32? Or do I really have to mess with both WNetGetUniversalName and QueryDosDevice to get what I need?

    推荐答案

    是的,您需要独立解析驱动器号.

    Yes, you would need to resolve the drive letter independently.

    WNetGetUniversalName()接近,但仅适用于映射到实际UNC共享的驱动器号,但并非总是如此.没有一个API函数可以为您完成所有工作.

    WNetGetUniversalName() comes close, but only works for drive letters that are mapped to actual UNC shares, which is not always the case. There is no single API function that does all of the work for you.

    这篇关于将Windows驱动器号解析为路径(替代和网络)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆