Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing Ownership 1

Status
Not open for further replies.

woodrasj

IS-IT--Management
Jun 17, 2002
27
US
I have searched and searched but can't find a way to tell who is the owner of a file.

Here is the situation I have.

I am looking through my disk quota's on one of my drives and I have a couple entries that show no account information available for the name and the logon gives a SID. What I would like to do is be able to input the SID and have it pull a list of file names for me so I can try and track down who the old user was that was using the files and find out if they are still needed or not.

If someone could give me something to start with I can usually figure it out but I have no idea even what the command would be.

I am using XP so I can acutally use the AdsSecurityUtility.

Thanks,

John
 
woodrasj:

I don't know if this relates to your current situation but when I worked with a Novell server a missing file owner meant that a file was owned by a user whose account had been deleted or corrupted. I was told then that the only way to determine who owned a file like this would be to keep a database of users that had been deleted from the system.
 
I really don't care who owns them for sure because by looking at most of them I can probably figure it out but the problem is is finding them.

I am pretty sure it is probably someone who has had their account deleted but without knowing where the files are I can't tell what can be kept or not and since the user is gone I would guess most of it will be able to be deleted.

Talking to a friend of mine he said that he had come across a way to search files and see who owns them but this would return the SID only he said which is fine. He couldn't remember where he read it and I can't find anything on the subject really.

Thanks,

John
 
I found some code and made it this far but could somebody help me with checking all the subfolders too.

Code:
set objShell = CreateObject ("Shell.Application")
set objFolder = objShell.Namespace ("c:\drivers")
set objFSO = CreateObject("scripting.fileSystemObject")
dim arrHeaders(13)

set outputFile = objFSO.OpenTextFile ("C:\OwnerLog.txt",2,True)

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
			outPutFile.Writeline arrheaders(i) _
			& &quot;: &quot; & objFolder.GetDetailsOf(strFileName,i)
		end if
	next
	
	
next

Thanks,

John
 
See if this helps:
thread329-494942

You will need to hack up the code a bit for your own purposes, but doing a recursive search through all of the subfolders is what it looks like you need.
 
Here is a subroutine that goes through every subfolder and checks file attributes.. it does this by calling the subroutine again for any subfolders found in the folder. (notice the line that says 'ShowSubFolders Subfolder') you could probably modify this to meet your needs.

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders

set osubfolder = oFSO.GetFolder(Subfolder.Path)
set FileCol = osubFolder.Files

for each fil in filecol

if datediff(&quot;d&quot;, fil.DateLastModified, strDate) > 0 then
strfilecount = strfilecount + 1
strFileSize = strFileSize + fil.size

end if
next

ShowSubFolders Subfolder
Next
End Sub
 
I ended up writing two scripts for this project. All I wanted to do was find where some files were located for a nonexistent user that showed up in the quota manager only as a SID.

First script compiles a list of folders for the drive.
Code:
set objFSO = CreateObject(&quot;scripting.fileSystemObject&quot;)
set outputFile = objFSO.OpenTextFile (&quot;C:\Folderlist.txt&quot;,2,True)

strComputer = &quot;.&quot;
set objWMIService = Getobject(&quot;winmgmts:&quot; _
	& &quot;{impersonationlevel = impersonate}!\\&quot; & strComputer & &quot;\root\cimv2&quot;)
set colFolders = objWMIService.ExecQuery(&quot;Select * from win32_Directory where name like '%i:\\%'&quot;)
for each objFolder in ColFolders
	outputfile.writeline objFolder.name
next
outputfile.close
wscript.echo &quot;DONE&quot;

Simple enough the only thing that really needs to change everytime is the drive letter in the SQL statement.

The second script
Code:
set objShell = CreateObject (&quot;Shell.Application&quot;)

set objFSO = CreateObject(&quot;scripting.fileSystemObject&quot;)

set inputFile = objFSO.OpenTextFile(&quot;c:\folderlist.txt&quot;,1)
set outputFile = objFSO.OpenTextFile (&quot;C:\OwnerLog.txt&quot;,2,True)
	

dim arrHeaders(13)
dim arrIndex(2)

while not inputfile.atendofstream
	folder = inputfile.readline
		set objFolder = objShell.Namespace (folder)
			for i = 0 to 13
				arrheaders(i) = objFolder.getDetailsof (objFolder.Items,I)
			next
			
		arrIndex(1) = &quot;1&quot;
		arrIndex(2) = &quot;8&quot;

			for each strfilename in objfolder.items
				outputFile.writeline &quot;File Path: &quot; & folder  
					for i = 0 to 2
'		if i <> 9 then
		
						outPutFile.Writeline arrHeaders(arrIndex(i)) _
						& &quot;: &quot; & objFolder.GetDetailsOf(strFileName,arrIndex(i))
'		end if
					next
	
			next

wend
wscript.echo &quot;Processing Complete&quot;
An afterthought that would be simple to do is to put this into a CSV file so you can sort it in excel but for I was using it for it worked well.

Just thought I would share what came about from this.

Thanks for the help again,

John
 
Here's the script I use
Code:
' **** Script start ****
' WMI script that gets all files in a
' specific subfolder and all its subfolders.
' Author: Torgeir Bakken
' Modified by : Carl Chipman

' find the files not owned by this person
desiredOwner = &quot;cchipman&quot;

' Start folder, do NOT add a trailing backslash!
sFolder = &quot;Z:&quot;

sComputer = &quot;.&quot; ' use &quot;.&quot; for local computer

' check command line parameters
if WScript.Arguments.Count < 3 Then
   WScript.Echo &quot;Insufficient Parameters&quot;
   WScript.Echo &quot;usage:&quot;
   WScript.Echo &quot;    cscript ownedby.vbs <root_path_no_trailing_backslash> <owner> <computer> [not]&quot;
   WScript.Quit(1)
Else
	sFolder =  WScript.Arguments(0)
	desiredOwner = WScript.Arguments(1)
	sComputer =  WScript.Arguments(2)
	notFlag = false
	If WScript.Arguments.Count > 3 Then
		If WScript.Arguments(3) = &quot;not&quot; Then
			notFlag = true
		Else
			notFlag = false
		End If
	End If
End If

Set oWMI = GetObject(&quot;winmgmts:&quot; _
& &quot;{impersonationLevel=impersonate}!\\&quot; & sComputer & &quot;\root\cimv2&quot;)

Set oDir = oWMI.Get(&quot;Win32_Directory='&quot; & sFolder & &quot;'&quot;)

' Get the files into an array
aFiles = Array()

EnumFolders oDir, oWMI, aFiles

WScript.Echo &quot;# of files found: &quot; & UBound(aFiles) + 1 & vbCrLf

WScript.Echo &quot;Checking ownership&quot;


For i = 0 To UBound(aFiles)
	On Error Resume Next
'	WScript.Echo aFiles(i)

	strQuery = &quot;ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=&quot; & _
				&quot;'&quot; & aFiles(i) & &quot;'} WHERE &quot; & _
				&quot;AssocClass=Win32_LogicalFileOwner &quot; & _
				&quot;ResultRole=Owner&quot;

'	WScript.Echo strQuery
	Set colOwner = oWMI.ExecQuery(strQuery)


	
	For Each refItem in colOwner
		If Err = 0 Then
			If CBool(refItem.AccountName <> desiredOwner) = notFlag Then
				WScript.Echo aFiles(i) & &quot; is owned by &quot; & refItem.AccountName
			End If
		Else
			WScript.Echo &quot;Cannot find owner for &quot; & aFiles(i)
		End If
	Next
Next



Sub EnumFolders(oDir, oWMI, aFiles)
	Set colSubDir = oWMI.ExecQuery( _
		&quot;Associators of {Win32_Directory.Name='&quot; & oDir.Name & &quot;'} &quot; _
		& &quot;Where AssocClass=Win32_SubDirectory ResultRole=PartComponent&quot;)
	
	On Error Resume Next

	For Each oSubDir in colSubDir
		EnumFolders oSubDir, oWMI, aFiles
	Next
	On Error Goto 0
	
	' Get a collection of files in this directory
	Set colFiles = oWMI.ExecQuery( _
		&quot;Associators of {Win32_Directory.Name='&quot; & oDir.Name & &quot;'} &quot; _
		& &quot;Where ResultClass=CIM_DataFile&quot;)
	
	' Enumerate files
	For Each oFile in colFiles
		'WScript.Echo oFile.Name
		i = UBound(aFiles) + 1
		ReDim Preserve aFiles(i)
		aFiles(i) = oFile.Name
	Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top