Find File Owner?

R

Roger Abell

This is on the Owner tab in the Advanced view within
the Security dialog that is found in the Properties of the
file. In Home edition you must be in a safe mode boot
to access this Security dialog.
 
A

Alan

Thanks Roger - that solved the problem. Is there a non-
safe mode solution for XP Home to save me booting to safe
mode?
 
T

Torgeir Bakken (MVP)

Alan said:
Thanks Roger - that solved the problem. Is there a non-
safe mode solution for XP Home to save me booting to safe
mode?

Hi

Try this:

Create a file called GetOwner.vbs containing the script below and
create a shortcut to it in the SendTo folder (or just put the file
itself in the SendTo folder, but then you will see the .vbs extension,
at least if you have set Explorer to show file extensions).

This way, you can select one or several files in Explorer, right click
on them and use the SendTo selection GetOwner. If you want to get the
result into the clipboard, just press Ctrl+C on the dialog box.

To open the SendTo folder, run this from the Start\Run menu (include
the quotes!):

"%USERPROFILE%\SendTo"


GetOwner.vbs:

'--------------------8<----------------------
Set oArgs = WScript.Arguments
If oArgs.Count = 0 Then
MsgBox "Error: You need to supply one or more file name(s) " _
& "as input parameter(s)!", vbSystemModal, "GetOwner"
Wscript.Quit
End If

sStr = "<file>: <owner>" & vbCrLf
For i = 0 To oArgs.Count - 1
sStr = sStr & oArgs(i) & ": " _
& GetOwner(oArgs(i)) & vbCrLf
Next

WScript.Echo sStr

If InStr(1, WScript.FullName, "cscript.exe", vbTextCompare) > 0 Then
MsgBox "Finished", vbSystemModal, "GetOwner"
End If


Function GetOwner(sFile)
sComputer = "."
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

On Error Resume Next

Set oCollection = oWMI.ExecQuery _
("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & sFile _
& "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")

For Each oSID in oCollection
GetOwner = oSID.AccountName
Next

If VarType(GetOwner) = 0 Then
GetOwner = "error"
End If
End Function
'--------------------8<----------------------


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx
 
A

Alan

Great! I'll give that a try. Thanks a lot Torgeir!!!
-----Original Message-----


Hi

Try this:

Create a file called GetOwner.vbs containing the script below and
create a shortcut to it in the SendTo folder (or just put the file
itself in the SendTo folder, but then you will see the .vbs extension,
at least if you have set Explorer to show file extensions).

This way, you can select one or several files in Explorer, right click
on them and use the SendTo selection GetOwner. If you want to get the
result into the clipboard, just press Ctrl+C on the dialog box.

To open the SendTo folder, run this from the Start\Run menu (include
the quotes!):

"%USERPROFILE%\SendTo"


GetOwner.vbs:

'--------------------8<----------------------
Set oArgs = WScript.Arguments
If oArgs.Count = 0 Then
MsgBox "Error: You need to supply one or more file name (s) " _
& "as input parameter(s)!", vbSystemModal, "GetOwner"
Wscript.Quit
End If

sStr = "<file>: <owner>" & vbCrLf
For i = 0 To oArgs.Count - 1
sStr = sStr & oArgs(i) & ": " _
& GetOwner(oArgs(i)) & vbCrLf
Next

WScript.Echo sStr

If InStr(1, WScript.FullName, "cscript.exe", vbTextCompare) > 0 Then
MsgBox "Finished", vbSystemModal, "GetOwner"
End If


Function GetOwner(sFile)
sComputer = "."
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")

On Error Resume Next

Set oCollection = oWMI.ExecQuery _
("ASSOCIATORS OF
{Win32_LogicalFileSecuritySetting='" & sFile _
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top