为什么我对 CIM_LogicalDisk 事件的 WMI 查询返回 Win32_LogicalDisk 事件而不返回 Win32_MappedLogicalDisk 事件?

发布于 2024-11-16 13:42:04 字数 1843 浏览 5 评论 0 原文

我有一个 System.Management.WqlEventQuery 监听“__InstanceOperationEvent” 事件。此事件是 "__InstanceCreationEvent""__InstanceDeletionEvent""__InstanceModificationEvent" 事件的基类,因此它捕获所有三个事件。

当我的 WqlEventQuery.Condition“TargetInstance ISA 'Win32_LogicalDisk'” 时,我仅收到逻辑磁盘的事件,如预期的那样。

但是,当我的 WqlEventQuery.Condition“(TargetInstance ISA 'Win32_LogicalDisk' 或 TargetInstance ISA 'Win32_MappedLogicalDisk')” 时,我仍然只得到 Win32_LogicalDisk事件。 或者,我还应该能够使用 WqlEventQuery.Condition 设置为 "TargetInstance ISA 'CIM_LogicalDisk'",因为 CIM_LogicalDiskWin32_LogicalDiskWin32_MappedLogicalDisk。不幸的是,这个替代查询也只返回 Win32_LogicalDisk 事件。

总之,我似乎无法捕获 Win32_MappedLogicalDisk 事件。我的假设是,当我右键单击网络共享并将其作为网络驱动器映射到新驱动器号时,应该生成此类事件。尽管这个新的映射驱动器在资源管理器中显示得很好,但我的程序从未收到任何事件。

我的任何假设都是错误的吗?什么是 Win32_MappedLogicalDrive 或者它与 Win32_LogicalDrive DriveType 是“NetworkDrive”吗?如何使用 WMI 捕获连接/断开网络驱动器的事件?

更新:我在这里发布了有关此问题的更多信息:http://social.technet.microsoft.com/Forums/en-US/ocsmanagement/thread/1c92f08b-b9c9-4f27-a1bb-0c16a8868d19事实证明这是一个不幸的一面 - UAC 的影响,除了在管理帐户下创建重复的驱动器映射之外,没有其他解决办法。

I have a System.Management.WqlEventQuery listening for the "__InstanceOperationEvent" event. This event is the base class for the "__InstanceCreationEvent", "__InstanceDeletionEvent", and "__InstanceModificationEvent" events, so it captures all three.

When my WqlEventQuery.Condition is "TargetInstance ISA 'Win32_LogicalDisk'", I get events for logical disks only, as expected.

However, when my WqlEventQuery.Condition is "(TargetInstance ISA 'Win32_LogicalDisk' or TargetInstance ISA 'Win32_MappedLogicalDisk')", I still get only Win32_LogicalDisk events.
Alternatively, I should also be able to use WqlEventQuery.Condition set as "TargetInstance ISA 'CIM_LogicalDisk'", because CIM_LogicalDisk is the base class for both Win32_LogicalDisk and Win32_MappedLogicalDisk. Unfortunately, this alternative query also returns only Win32_LogicalDisk events.

In summary, I cannot seem to capture Win32_MappedLogicalDisk events. My assumption is that such an event should be generated when I right click a network share and map it as a network drive to a new drive letter. Despite this new mapped drive showing up in Explorer just fine, my program never receives any event.

Are any of my assumptions wrong? What is a Win32_MappedLogicalDrive or what distinguishes it from a Win32_LogicalDrive whose DriveType is "NetworkDrive"? How can I capture events for connecting/disconnecting network drives using WMI?

UPDATE: I posted more on this problem here: http://social.technet.microsoft.com/Forums/en-US/ocsmanagement/thread/1c92f08b-b9c9-4f27-a1bb-0c16a8868d19 It's turning out to be an unfortunate side-effect of UAC, with no work around except to create duplicate drive mappings under an administrative account.

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

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

发布评论

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

评论(1

£烟消云散 2024-11-23 13:42:04

我四处搜寻,发现这是(像往常一样)某种与 Vista/Window 7 UAC 相关的行为,当然…… http://www.vistax64.com/powershell/270814-win32_mappedlogicdisk-returns-null-vista.html

由于映射驱动器是“每个用户”的,因此由非提升的驱动器映射的驱动器以管理员身份运行的 WMI 查询无法看到用户(例如,来自资源管理器)。这是违反直觉的,因为通常应用程序可以访问以管理员身份运行的更多信息,而不是更少。因此,根据谁映射了驱动器,它可能对程序可见,具体取决于它是否以提升的权限运行。我想我将不得不使用模拟选项来确保程序找到它可能访问的所有驱动器。

此外,一旦工作正常,我看到网络驱动器的重复条目,并意识到 Win32_LogicalDisk 对象集包括 Win32_MappedLogicalDisk 对象,即使就任何类层次结构而言,Win32_MappedLogicalDIsk 都不是 Win32_LogicalDisk。根据文档,Win32_MappedLogicalDisk 与 Win32_LogicalDisk 一样,直接从 CIM_LogicalDisk 扩展。

请参阅此处有关映射驱动器 UAC 引起的问题的讨论:http://blogs.msdn.com/b/cjacks/archive/2007/02/19/mapped-network-drives-with-uac-on-windows-vista.aspx?PageIndex=2< /a>

摘录:

“我的存根正在以管理员身份运行。
你是否建议以某种方式它可以
检测标准用户的驱动力
已经映射,然后进行映射
再次?或者我需要两个存根:
第一次运行没有海拔,a
列出(例如,到注册表)
映射的驱动器,然后外壳
存根#2,要求提升到
admin,读取注册表列表并
重新映射驱动器。 听起来有点像
对我来说就像鲁布·戈德堡!

另一种解决方法有点像为管理员复制驱动器映射,但涉及允许普通用户通过链接令牌与管理员共享驱动器映射。请参阅 http://support.microsoft.com/kb/937624

I searched around figuring this was (as usual) some kind of Vista/Window 7 UAC-related behavior, and sure-enough... http://www.vistax64.com/powershell/270814-win32_mappedlogicaldisk-returns-null-vista.html

Since mapped drives are "per user", a drive mapped by a non-elevated user (e.g. from Explorer) cannot be seen by a WMI query running elevated as administrator. That's counter-intuitive, because usually an application can access more information running as an administrator, not less. So depending on who mapped the drive, it may be visible to a program depending on whether it's running with elevated privileges or not. I guess I will have to use the impersonation options to ensure the program locates all the drives it can possibly access.

In addition, once this was working, I saw duplicate entries for networked drives and realized that the set of Win32_LogicalDisk objects includes Win32_MappedLogicalDisk objects, even though Win32_MappedLogicalDIsk is not a Win32_LogicalDisk as far as any class hierarchy is concerned. Win32_MappedLogicalDisk, like Win32_LogicalDisk, extends directly from CIM_LogicalDisk according to the documentation.

See discussion on problems caused by UAC for mapped drives here: http://blogs.msdn.com/b/cjacks/archive/2007/02/19/mapped-network-drives-with-uac-on-windows-vista.aspx?PageIndex=2

Excerpt:

"My stub is running elevated to admin.
Are you suggesting that somehow it can
detect what drives the standard user
had mapped, and then do the mapping
again? Or do I need two stubs: the
first runs without elevation, a
makes a list (say, to the registry) of
the mapped drives, then shells out to
stub #2, which asks for elevation to
admin, reads the registry list and
re-maps the drives. Sounds kinda
Rube Goldberg-like to me!
"

Another workaround is kind of like duplicating the drive mappings for administrators, but involves allowing normal user drive mappings to be shared with administrators by linking thier tokens. See http://support.microsoft.com/kb/937624

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