请参阅/选择只根据其标签的驱动器? (即,而不是驱动器盘符) [英] Refer to/select a drive based only on its label? (i.e., not the drive letter)

查看:104
本文介绍了请参阅/选择只根据其标签的驱动器? (即,而不是驱动器盘符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想引用一个驱动器盘符,其可能改变。我想用它的标签(例如,MyLabel(V :)批处理文件中可以用V简称参考吧:。\\我想用MyLabel引用它

I'm trying to refer to a drive whose letter may change. I'd like to refer to it by its label (e.g., MyLabel (v:) within a Batch File. It can be referred to by V:\ . I'd like to refer to it by MyLabel.

(这是张贴在专家外汇牌价对于没有答案了一个月。让我们看看如何快,所以它回答)

(This was posted on Experts Echange for a month with no answer. Let's see how fast SO answers it )

推荐答案

此bat文件将会给您从硬盘标签的驱动器盘符:

This bat file will give you the drive letter from a drive label:

Option Explicit
Dim num, args, objWMIService, objItem, colItems

set args = WScript.Arguments
num = args.Count

if num <> 1 then
   WScript.Echo "Usage: CScript DriveFromLabel.vbs <label>"
   WScript.Quit 1
end if

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

For Each objItem in colItems
  If strcomp(objItem.VolumeName, args.Item(0), 1) = 0 Then
    Wscript.Echo objItem.Name
  End If
Next

WScript.Quit 0

运行它:

 cscript /nologo DriveFromLabel.vbs label

这篇关于请参阅/选择只根据其标签的驱动器? (即,而不是驱动器盘符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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