在 WQL 中返回服务器上安装的驱动器

发布于 2024-07-30 07:28:09 字数 739 浏览 5 评论 0原文

我正在尝试创建一个简单的 WQL 查询,其中仅返回服务器上已安装的驱动器。 这些驱动器没有与其关联的驱动器盘符。

我尝试了以下 sytnax,但它不返回结果集:

SELECT * FROM Win32_Volume WHERE DriveLetter = ""

这是 C# 中的完整代码示例:

string ManagementPath = string.Format(@"\\{0}\root\CIMV2", txtServerName.Text);
ConnectionOptions DriveConnOptions = new ConnectionOptions();
ObjectQuery oq = new ObjectQuery(@"SELECT * FROM Win32_Volume WHERE DriveLetter = """"");
ManagementScope Scope = new ManagementScope(ManagementPath, DriveConnOptions);
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, oq);
ManagementObjectCollection collection = Searcher.Get();
foreach (ManagementObject mo in collection)
{
    //do something...
}

I am trying create a simple WQL query where I only return mounted drives on a server. These are drives that do not have a drive letter associated with them.

I tried the following sytnax and it does not return a result set:

SELECT * FROM Win32_Volume WHERE DriveLetter = ""

Here is the complete code sample in C#:

string ManagementPath = string.Format(@"\\{0}\root\CIMV2", txtServerName.Text);
ConnectionOptions DriveConnOptions = new ConnectionOptions();
ObjectQuery oq = new ObjectQuery(@"SELECT * FROM Win32_Volume WHERE DriveLetter = """"");
ManagementScope Scope = new ManagementScope(ManagementPath, DriveConnOptions);
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, oq);
ManagementObjectCollection collection = Searcher.Get();
foreach (ManagementObject mo in collection)
{
    //do something...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮光之海 2024-08-06 07:28:09

我需要将 WQL 语句更改为:

SELECT * FROM Win32_Volume WHERE DriveLetter IS NULL

I need to change my WQL statement to:

SELECT * FROM Win32_Volume WHERE DriveLetter IS NULL
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文