小编Ric*_*ick的帖子

在C#中获取驱动器标签

当我使用System.IO.DriveInfo.GetDrives()并查看.VolumeLabel其中一个驱动器的属性时,我看到"PATRIOT XT",这确实是驱动器的卷标.

如果我打开"我的电脑",而不是我看到"TrueCrypt Traveler磁盘",我似乎无法找到任何方式以编程方式检索该值,因为没有任何DriveInfo属性保存该值.我也试过通过WMI查询信息Win32_LogicalDisk,但是没有属性包含那个值.

那么任何想法My Computer使用的标签都被称为,更重要的是,如何以编程方式检索它?

编辑:要清楚,这是我正在使用的代码,然后是它输出的内容,接下来是我在"我的电脑"中看到的内容(这是我要复制的内容):

foreach (DriveInfo DI in DriveInfo.GetDrives())
    richTextBox1.AppendText(
        (
            DI.IsReady ?
            (DI.VolumeLabel.Length == 0 ? DI.DriveType.ToString() : DI.VolumeLabel) :
            DI.DriveType.ToString()
        )
        +
        " (" + DI.Name.Replace("\\", "") + ")"
        + Environment.NewLine
    );
Run Code Online (Sandbox Code Playgroud)
Removable (A:)
Fixed (C:)
CDRom (D:)
PATRIOT XT (E:)
Backup (Y:)
Data (Z:)

我的电脑详情视图显示:

Floppy Disk Drive (A:)
Local Disk (C:)
DVD RW Drive (D:)
TrueCrypt Traveler Disk (E:)
Backup (Y:)
Data (Z:)

c# drive

13
推荐指数
2
解决办法
9958
查看次数

使用Mono的另一个进程使用套接字描述符

我有一个用C#编写的BBS门,我想在Linux上工作..NET框架的Socket类不支持打开现有的套接字句柄,因此需要为Windows和Linux实现不同的解决方法.

对于Linux,我查看了Socket.cs文件,看到这发生在DuplicateAndClose()中:

var si = new SocketInformation ();
si.Options =
    (islistening ? SocketInformationOptions.Listening : 0) |
    (connected ? SocketInformationOptions.Connected : 0) |
    (blocking ? 0 : SocketInformationOptions.NonBlocking) |
    (useoverlappedIO ? SocketInformationOptions.UseOnlyOverlappedIO : 0);

si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", 
    (int)address_family, 
    (int)socket_type, 
    (int)protocol_type, 
    isbound ? 1 : 0, 
    (long)socket);

socket = (IntPtr) (-1);

return si;
Run Code Online (Sandbox Code Playgroud)

由于我无法从Windows访问Mono.DataConverter,因此我也查看了它的来源,并提出了以下建议:

SocketInformation SI = new SocketInformation();
SI.Options = SocketInformationOptions.Connected;
SI.ProtocolInformation = new byte[24];

Int32 AF = (Int32)AddressFamily.InterNetwork;
Int32 ST = (Int32)SocketType.Stream;
Int32 PT = (Int32)ProtocolType.Tcp;
Int32 Bound = …
Run Code Online (Sandbox Code Playgroud)

.net c# sockets linux mono

5
推荐指数
0
解决办法
1124
查看次数

标签 统计

c# ×2

.net ×1

drive ×1

linux ×1

mono ×1

sockets ×1