Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scripting help... get list of files with owner and date
Message
General information
Forum:
Windows
Category:
Administration & Security
Miscellaneous
Thread ID:
01108105
Message ID:
01108443
Views:
19
Alex,

>Where did you learn to program this? I have been looking for references but I don't even know where to start. *grin*

I do not know how to program, I just steal some code from here and some code from there, google is your friend, well, at least it is mine.

Back to your problem, and just to show you how to steal code, let's steal Craig's code (In my defense I would say Craig deserved to be stolen, for he did not read any of the previous posts or even look at where your question was posted! <g>)
Option Explicit

Dim oArgs, oRootFolder, oFSO, oFolder, nSize, nDays

Set oArgs = WScript.Arguments

if oArgs.Count = 0 then
	WScript.Echo "Folder name required"
end if

Set oFSO = CreateObject("Scripting.FileSystemObject")
on error resume next
Set oRootFolder = oFSO.GetFolder(oArgs(0))
On Error Goto 0

if oArgs.Count = 2 then
	nSize = clng(oArgs(1))
else
	nSize = 10000
end if

if oArgs.Count = 3 then
	nDays = cInt(oArgs(2))
else
	nDays = 1
end if

if IsObject(oRootFolder) then
	CheckFiles oRootFolder, nSize, nDays
else
	WScript.Echo "Folder " & oArgs(0) & " not found"
end if


Sub CheckFiles(oFolder, nSize, nDays)

Dim oFile

for each oFile in oFolder.Files
	if oFile.Size >= nSize and DateDiff("d", oFile.DateCreated, Now) <= nDays  then
		WScript.Echo oFile.Path & "  " & oFile.Size & "  " & oFile.DateCreated & "  " & DateDiff("d", oFile.DateCreated, Now) & "   Owners: " & getListOfOwners(oFile.Path)
	end if
next
for each oFolder in oFolder.SubFolders
	CheckFiles oFolder, nSize, nDays
next
end sub


Function getListOfOwners(cFile)
dim oWMI, oAssociators, cList, oInfo
Set oWMI = GetObject("winmgmts:")

On Error Resume Next

Set oAssociators = oWMI.ExecQuery("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & cFile & "'} WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
On Error Goto 0

cList = ""
if IsObject(oAssociators) then
	For Each oInfo in oAssociators
		cList = cList + oInfo.AccountName + ","
	Next
end if

If len(cList)= 0 Then
	getListOfOwners = "Unable to retrieve ownership"
else
	getListOfOwners = Left(cList, len(cList) - 1)
End If
End Function
(I know this is not still exactly what you want, if I find some time I will try to get back to this)
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform