设置Drive VolumeLabel
我正在开发一个小实用程序,我想更改连接到计算机的闪存驱动器上的卷标。 我知道DriveInfo能够做到这一点,但我不知道如何实现它。 如果有人有代码示例我会非常感激。
这是我目前拥有的:
DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady && d.DriveType == DriveType.Removable) { //set volume label here } }
谢谢詹姆斯! 我不知道为什么我有这么多问题,但是你让我走上了正确的道路。
以下是设置驱动器标签的最终代码。 对于使用此function的任何其他人,它将更改连接到系统的任何可移动驱动器的名称。 如果只需要更改特定驱动器型号的名称,可以使用WMI的Win32_DiskDrive
来缩小范围。
public void SetVolumeLabel(string newLabel) { DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady && d.DriveType == DriveType.Removable) { d.VolumeLabel = newLabel; } } } public string VolumeLabel { get; set; } // Setting the drive name private void button1_Click(object sender, EventArgs e) { SetVolumeLabel("FlashDrive"); }
你试过DriveInfo.VolumeLabel吗?
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.volumelabel.aspx
- 通过在datagridviewcolum中指定DefaultCellStyle.Format值来显示百分比
- 在C#/ GDI +中从Format8bppIndexed转换为Format24bppRgb
- 在.NET中组合多个PNG8图像的最简单方法
- 在VB.NET中检查使用process.start()启动的文件中的更改
- 我如何unit testing这种(正确)抛出exception的异步方法?
- Awesomium Webview Surface to Byte Buffer或PictureBox
- 每天在特定时间执行一些代码
- Google API / OAUTH / NativeApplicationClient / OAuth2Authenticator>退出?
- 在C#/ .NET 4.0中新的NoPIA和Type Equivalencefunction是否意味着不再需要Microsoft.mshtml.dll
- 以编程方式修改端点ReaderQuotas
- C#编译器是否足够智能以优化此代码?