使用VBS关联器检查文件夹

时间:2017-12-18 10:23:04

标签: vbscript wmi wmi-query wql

我需要找出文件夹的路径是否包含隐藏文件夹。 有谁知道怎么做?我必须使用关联者。现在我的脚本只显示隐藏或不隐藏的确切文件夹,而不检查它的路径。

Dim xdoc

Function CreateFolders(objFile)
    Dim elem
    Dim attr
    Set elem = xdoc.CreateElement("Folder")
    Set attr = xdoc.CreateAttribute("Description")
    attr.Value = objFile.Description
    elem.SetAttributeNode attr
    Set CreateFolders = elem
End Function

Dim FilePath
Dim objFile
Dim root
Dim elem, elem1
Dim FilePath2

Set oFSO = CreateObject("Scripting.FileSystemObject")

If WScript.Arguments.Count > 0 Then
    sFile = WScript.Arguments(0)

    If oFSO.FileExists(sFile) Then
        Set oFile = oFSO.GetFile(sFile)
        sModify = oFile.DateLastModified
    End If
End If
FilePath2 = WScript.Arguments(0)

Set xdoc = CreateObject("MSXML2.DOMDocument.6.0")
xdoc.AppendChild xdoc.CreateProcessingInstruction("xml", "version=""1.0"" encoding=""utf-8""")
FilePath = "C:\Users\User\Downloads\My123.xml"

Set root = xdoc.CreateElement("Folders")
xdoc.AppendChild root

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Directory WHERE Name = '" & FilePath2 & "'")

For Each objFile In colFiles
    Wscript.Echo objFile.Name & "  " & "Status: "  & objFile.Hidden
    Set elem = CreateFolders(objFile)
    root.AppendChild elem
Next

xdoc.Save FilePath

0 个答案:

没有答案