1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: vbScript File Owner

Discussion in 'Software Development' started by draceplace, Sep 24, 2008.

Thread Status:
Not open for further replies.
  1. draceplace

    draceplace Thread Starter

    Joined:
    Jun 8, 2001
    Messages:
    2,583
    How do I get the file owner in a vbscript? In DOS you see the file owner with "dir /Q " . I can't find the VB equivant!!

    Wow!, can't believe this question is that hard...I'm looking for a "objFile.Size" like property "objFile.Owner" except that's not it. I've Googled and looked but I'm missing it somehow. surely someone here knows this!!

    Thanks for reading my post!!
     
  2. draceplace

    draceplace Thread Starter

    Joined:
    Jun 8, 2001
    Messages:
    2,583
    Public strFileOwner

    Sub GetFileOwner(strFile)
    Set colItems = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & strFile & "'}" _
    & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
    For Each objItem in colItems
    ' Wscript.Echo objFile.Name & " " & objItem.AccountName
    strFileOwner = objItem.AccountName
    Next
    End Sub
     
  3. draceplace

    draceplace Thread Starter

    Joined:
    Jun 8, 2001
    Messages:
    2,583
    Found out you should check for nulls and empties before you execute. Short cuts and other junk in a directory will cause it to fail....Also so another that seems it would work:

    Set objShell = CreateObject ("Shell.Application")
    Set objFolder = objShell.Namespace ("C:\aScripts\origionals")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim arrHeaders(13)
    For i = 0 to 13
    arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
    Next
    For Each strFileName in objFolder.Items
    For i = 0 to 13
    If i <> 9 then
    Wscript.echo arrHeaders(i) _
    & ": " & objFolder.GetDetailsOf (strFileName, i)
    End If
    Next
    Wscript.Echo
    Next
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/752986

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice