Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Get Ownership of file using WMI

mevasquez (Programmer)
21 Jun 06 18:00
Having problems with the following script.  When the variable fName is a path such as, c:\Folder\subFolder, p:\folder\subfolder, the script works.  When the variable fName is a path such as \\domainFileServer\folder\Subfolder, I get an automation error.  Any suggestions

CODE

Function getOwner(fName)

    Dim strComputer
    Dim objWMIService
    Dim colItems
    Dim objItem
    
    strComputer = "."
             
    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
        getOwner = getDisplayName(objItem.AccountName)
    Next
End Function

Public Function getDisplayName(ByVal vSAN)
    
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
    ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));DisplayName;subtree"
    Set oRecordSet = oCommand.Execute

    getDisplayName = oRecordSet.Fields("DisplayName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function
tsuji (TechnicalUser)
22 Jun 06 7:00
The wmi service object should bind you to the remote (file) server. From there you can specify a (local) fully-qualified path.

Function getOwner(domainFileServer, fName)
    'here fName is the (local, unescaped) fully-qualified path to file or directory

    'etc etc

    strComputer = domainFileServer
             
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colItems = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & fName & "'}" _
            & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
    'etc etc

mevasquez (Programmer)
22 Jun 06 16:43
I still get the error, automation error, at
...

CODE


strComputer = "DomainComputerName"

GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
...
tsuji (TechnicalUser)
22 Jun 06 21:56
Associator query is not normally one starts with wmi. What simple wmi script you can do on the domainfileserver without automation error? What error number? Do you have enough credential to bind to it? Are you logged on to the domain?...

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close