Windows 中的最大驱动器数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1944877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maximum number of drives in windows?
提问by laura
I'm trying to figure out the available disk space programmatically in windows. For this, I need to first get a list of the available drives, then check which of those are local drives and then query the available bytes on each local drive.
我试图在 Windows 中以编程方式找出可用的磁盘空间。为此,我需要首先获取可用驱动器的列表,然后检查哪些是本地驱动器,然后查询每个本地驱动器上的可用字节。
I'm a bit stuck on the first part, where the API presents two functions:
我有点卡在第一部分,其中 API 提供了两个函数:
GetLogicalDrives
(http://msdn.microsoft.com/en-us/library/aa364972(VS.85).aspx) which gives you a DWORD with the bits set (bit 0 if drive A is present, bit 1 if drive B etc)GetLogicalDriveStrings
(http://msdn.microsoft.com/en-us/library/aa364975(VS.85).aspx) which gives you the actual strings.
GetLogicalDrives
(http://msdn.microsoft.com/en-us/library/aa364972(VS.85).aspx)它为您提供一个带有位设置的 DWORD(如果驱动器 A 存在,则为位 0,如果驱动器 B 则为位 1 等) )GetLogicalDriveStrings
(http://msdn.microsoft.com/en-us/library/aa364975(VS.85).aspx)它为您提供了实际的字符串。
Now, although I'll be using strings later on, I'd prefer using the first option for querying. However, on my system a DWORD is typedef-ed to "unsigned long", which is 4 bytes, whereas drive letters only range A-Z (26 - i think - characters). Obviously, one can define more than 26 drives on their system (however unlikely they are to do so) - so I was wondering if there was any convention for those drives. Can someone point me to a resource on this?
现在,虽然稍后我将使用字符串,但我更喜欢使用第一个选项进行查询。但是,在我的系统上,DWORD 被 typedef-ed 为“unsigned long”,即 4 个字节,而驱动器号的范围仅为 AZ(26 - 我认为 - 字符)。显然,一个人可以在他们的系统上定义超过 26 个驱动器(但他们不太可能这样做) - 所以我想知道这些驱动器是否有任何约定。有人可以给我指点这方面的资源吗?
Thanks.
谢谢。
采纳答案by atzz
DWORD is always 4 bytes, regardless of the system (it's a Win32 type).
The maximum for drive lettersin Windows is 26. Because English alphabet has only 26 letters :). However, Windows allows two ways to mount a volume:
- to a drive letter
- to a directory (on an NTFS volume). You can mount one volume to multiple locations (but no more than one drive letter, IIRC). A GUI for this task is presented by Control Panel -> Administrative Tools -> Computer Management -> Disk Management.
无论系统如何(它是 Win32 类型),DWORD 始终为 4 个字节。
Windows 中驱动器号的最大值为26。因为英文字母只有 26 个字母 :)。但是,Windows 允许以两种方式安装卷:
- 到驱动器号
- 到一个目录(在 NTFS 卷上)。您可以将一个卷安装到多个位置(但不能超过一个驱动器号,IIRC)。此任务的 GUI 由Control Panel -> Administrative Tools -> Computer Management -> Disk Management 提供。
If you want to have more than 26 drives with the additional drives being redirectsto already active drives and are okay with them not working properly in most programs, then you can assign more with the following method (be warned they won't even show up in the file explorer):
如果您想要拥有超过 26 个驱动器,并且附加驱动器被重定向到已经处于活动状态的驱动器,并且它们在大多数程序中无法正常工作,那么您可以使用以下方法分配更多驱动器(请注意它们甚至不会出现在文件资源管理器中):
subst ?: C:\Temp\
cd /D ?:\
and to delete them (also they aren't preserved through restarts):
并删除它们(它们也不会通过重新启动保留):
subst /D ?:
You can enumerate all volumes and their mount points as described in this article.
您可以枚举所有卷及其安装点,如本文所述。
回答by Vinko Vrsalovic
回答by avakar
It it not sufficient to enumerate MS-DOS drives (there can be at most 26 of them, by the way, although each can be bound twice, once globally and once locally in your session), a volume can, for example, be mounted to a directory. What you want is probably to enumerate all volumes in the system, using FindFirstVolumeet al. Take a look at the associated MSDN example.
枚举 MS-DOS 驱动器是不够的(顺便说一下,最多可以有 26 个,尽管每个都可以绑定两次,一次全局绑定,一次在会话中本地绑定),例如,可以挂载一个卷到一个目录。您想要的可能是枚举系统中的所有卷,使用FindFirstVolume等。查看相关的 MSDN示例。