有人有对 CIM_DataFile 类进行 WMI 查询的示例代码吗?

发布于 2024-07-23 15:25:26 字数 72 浏览 7 评论 0原文

SELECT 可以获取有关文件或目录的信息吗? 确实有效的东西吗?

语言并不重要,我最感兴趣的是查询语法。

Something that does SELECT's to get info about a file or directory? Something that actually works?

Language doesn't matter, I'm most interested in the query syntax.

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

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

发布评论

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

评论(3

倾城月光淡如水﹏ 2024-07-30 15:25:26

以下是一些示例:

  • 查询文件:

    SELECT * FROM CIM_DataFile WHERE Name='C:\\WINDOWS\\NOTEPAD.EXE' 
      SELECT * FROM CIM_DataFile WHERE Drive='C:' AND Path='\\Windows\\' AND FileName='Notepad' AND Extension='EXE' 
      
  • 查询文件夹:

    从 CIM_Directory WHERE Name='C:\\Windows' 中选择 * 
      SELECT * FROM CIM_Directory WHERE Drive='C:' AND Path='\\Program Files\\' AND FileName='Internet Explorer' 
      

有关查询语法的详细信息,请参阅WQL(用于 WMI 的 SQL)。 另请参阅 CIM_DataFileCIM_Directory 查看文件和文件夹属性的列表可以在 SELECTWHERE 子句中使用。

Here're some examples:

  • Querying a file:

    SELECT * FROM CIM_DataFile WHERE Name='C:\\WINDOWS\\NOTEPAD.EXE'
    SELECT * FROM CIM_DataFile WHERE Drive='C:' AND Path='\\Windows\\' AND FileName='Notepad' AND Extension='EXE'
    
  • Querying a folder:

    SELECT * FROM CIM_Directory WHERE Name='C:\\Windows'
    SELECT * FROM CIM_Directory WHERE Drive='C:' AND Path='\\Program Files\\' AND FileName='Internet Explorer'
    

For more information on the query syntax, see WQL (SQL for WMI). Also see CIM_DataFile and CIM_Directory for a list of file and folder properties that can be used in the SELECT and WHERE clauses.

冷情妓 2024-07-30 15:25:26

我已经得到了答案,这一切都是由我的一个愚蠢的错误引起的:我未能在路径字符串中加倍反斜杠,并认为它已经完成。 此外,您必须在 WHERE 子句中指定所有四个字段:驱动器、路径、文件名和扩展名。

I have reached the answer, and it was all caused by a silly error of mine: I was failing to double the backslashes in the path string, and thinking it was being done. Additionally, you have to specify all four fields in the WHERE clause: drive, path, filename, and extension.

固执像三岁 2024-07-30 15:25:26

WMI 代码创建器 有一些帮助。
请参阅此代码:

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM CIM_DataFile",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "CIM_DataFile instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "AccessMask: " & objItem.AccessMask
    Wscript.Echo "Archive: " & objItem.Archive
    Wscript.Echo "LastAccessed: " & objItem.LastAccessed
    Wscript.Echo "LastModified: " & objItem.LastModified
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Path: " & objItem.Path
    Wscript.Echo "Readable: " & objItem.Readable
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "System: " & objItem.System
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo "Writeable: " & objItem.Writeable
Next

编辑

此示例是您正在查找的枚举计算机上的所有文件

尝试使用这种格式的查询:

Select * From Win32_Directory Where FileName = 'Scripts'

这里有关使用 LIKE 进行查询 WQL 的更多信息
也可以尝试一下:Scriptomatic 2.0

The WMI Code Creator has some help.
See this code:

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM CIM_DataFile",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "CIM_DataFile instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "AccessMask: " & objItem.AccessMask
    Wscript.Echo "Archive: " & objItem.Archive
    Wscript.Echo "LastAccessed: " & objItem.LastAccessed
    Wscript.Echo "LastModified: " & objItem.LastModified
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Path: " & objItem.Path
    Wscript.Echo "Readable: " & objItem.Readable
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "System: " & objItem.System
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo "Writeable: " & objItem.Writeable
Next

EDIT

This sample is that you are looking Enumerating All the Files on a Computer.

Try this format of query to:

Select * From Win32_Directory Where FileName = 'Scripts'

Here more info about make query WQL using LIKE.
Try this also: Scriptomatic 2.0 .

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