none
GetOwner - Script que obtem caminho, arquivo e Proprietário RRS feed

  • Pergunta

  • Peguei o script abaixo para me gerar um relatório de proprietários de arquivos em determinada pasta.
    Gostaria de saber se conseguir especificar o Proprietário para que me gere somente desse proprietário.

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = "x:\"
    LogFile = "c:\FileList.txt"
    strComputer = "."
    Set objLogFile = objFSO.CreateTextFile(logfile, 2, True)
    
    
    Set objFolder = objFSO.GetFolder(objStartFolder)
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
        objLogFile.WriteLine objFile.Path & ";" & objFile.Name & ";" & objFile.Size & ";" & getOwner(objFile.Path, strComputer)
    Next
    
    ShowSubfolders objFSO.GetFolder(objStartFolder)
    
    Sub ShowSubFolders(Folder)
        For Each Subfolder in Folder.SubFolders
            Set objFolder = objFSO.GetFolder(Subfolder.Path)
            Set colFiles = objFolder.Files
            For Each objFile in colFiles
          objLogFile.WriteLine objFile.Path & ";" & objFile.Name & ";" & objFile.Size & ";" & getOwner(objFile.Path, strComputer)
            Next
            ShowSubFolders Subfolder
        Next
    End Sub
    
    Function getOwner(fName, strComputer)
     On Error Resume next
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
        Set colItems = objWMIService.ExecQuery _
            ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & fName & "'}" _
                & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
        
        For Each objItem In colItems
            return = objItem.AccountName
      If Error <> 0 Then
       return = "Erro ao pegar o owner"
      End If
      getOwner = return
        Next
    End Function
    
    

    kiko
    terça-feira, 6 de outubro de 2009 14:08

Respostas

  • Olá,

    Faça o teste no script abaixo:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objStartFolder = "c:\teste\"
    LogFile = "c:\FileList.txt"
    strComputer = "."
    Set objLogFile = objFSO.CreateTextFile(logfile, 2, True)


    strOwner = "jesiel"


    Set objFolder = objFSO.GetFolder(objStartFolder)
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
        objLogFile.WriteLine objFile.Path & ";" & objFile.Name & ";" & objFile.Size & ";" & getOwner(objFile.Path, strComputer)
    Next

    ShowSubfolders objFSO.GetFolder(objStartFolder)

    Sub ShowSubFolders(Folder)
        For Each Subfolder in Folder.SubFolders
            Set objFolder = objFSO.GetFolder(Subfolder.Path)
            Set colFiles = objFolder.Files
            For Each objFile in colFiles
               if instr(uCASE( getOwner(objFile.Path, strComputer)),UCASE(strOwner)) > 0 Then
                  objLogFile.WriteLine objFile.Path & ";" & objFile.Name & ";" & objFile.Size & ";" & getOwner(objFile.Path, strComputer)
               End if
            Next
            ShowSubFolders Subfolder
        Next
    End Sub

    Function getOwner(fName, strComputer)
     On Error Resume next
        Set objWMIService = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

        Set colItems = objWMIService.ExecQuery _
            ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & fName & "'}" _
                & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
       
        For Each objItem In colItems
            return = objItem.AccountName
      If Error <> 0 Then
       return = "Erro ao pegar o owner"
      End If
      getOwner = return
        Next
    End Function




    Até mais,

    Jesiel

    Obs.: Se útil, classifique

    terça-feira, 6 de outubro de 2009 18:44