sirbounty
asked on
Trouble with script
Thanx to another expert, guidway, I was able to produce the following script:
It works great up until it comes in contact with a certain folder/file apparently.
I thought at first it was due to the folder being named with a "!" but I don't believe that's it. Presumably this scans alphabetically? If so, we go through the following folders before it stops:
!!!!MEU Pricing folder
!!Save_Florida_2003
!Thomas O'Malley
The last entry is a Hack.MDB in !!Save_Florida_2003 before it stops and errors on:
(66,6) (null): 0x8004103A
VERY GRATEFUL FOR ANY AND ALL ASSISTANCE WITH THIS!!! : )
Code below:
========================== ====
Dim FSO, oFil, s2, objArgs, objItem
Dim computerName, owner
Dim objFileSystem, objOutputFile
Dim strOutputFile
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set objNetwork = Wscript.CreateObject("Wscr ipt.Networ k")
computerName = objNetwork.ComputerName
strOutputFile = "e:\batch\" & computerName & "-db.lst"
Set objFileSystem = CreateObject("Scripting.fi leSystemOb ject")
Set objOutputFile = objFileSystem.CreateTextFi le(strOutp utFile, TRUE)
if fso.folderexists("g:\group s_1") then
set f = fso.getfolder("g:\groups_1 ")
elseif fso.folderexists("g:\group s") then
set f = fso.getfolder("g:\groups")
end if
call searchall(f)
if fso.folderexists("h:\group s_2") then
set f = fso.getfolder("h:\groups_2 ")
elseif fso.folderexists("h:\group s") then
set f = fso.getfolder("h:\groups")
end if
call searchall(f)
if fso.folderexists("i:\group s_3") then
set f = fso.getfolder("i:\groups_3 ")
elseif fso.folderexists("i:\group s") then
set f = fso.getfolder("i:\groups")
end if
call searchall(f)
Sub SearchFolder(byRef objFolder)
Dim objFile, objSubFolder
if not objFolder.name = "System Volume Information" then
For Each objFile in objFolder.Files
Call SearchFile(objFile)
next 'objFile
end if
if not objFolder.name = "System Volume Information" then
For Each objSubFolder in objFolder.SubFolders
Call SearchFolder(objSubFolder)
Next 'objSubFolder
end if
End Sub
Sub SearchAll(byVal strFolder)
dim objFSO, objFolder
' Setup the FSO Object
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
' Get the root folder
Set objFolder = objFSO.GetFolder(strFolder )
objOutputFile.WriteLine("S ERVER NAME" & vbTab & "CREATED" & vbTab & "LAST ACCESSED" & vbTab & "MODIFIED" & vbTab & "FILE NAME" & vbTab & "SIZE" & vbTab & "COMPLETE PATH" & vbTab & "OWNER")
Call SearchFolder(objFolder)
End Sub
Sub SearchFile(byVal oFil)
if right(oFil.name, 4) = ".mdb" then
' objOutputFile.WriteLine(oF il.path)
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecurity Setting='" & oFil.path & "'}" & " WHERE AssocClass=Win32_LogicalFi leOwner ResultRole=Owner")
For Each objItem in colItems
owner = objItem.AccountName
Next
' s2 = ""
s2 = Computername & vbTab & left(oFil.DateCreated, 10) & vbTab
s2 = s2 & left(oFil.DateLastAccessed , 10) & vbTab
s2 = s2 & left(oFil.DateLastModified , 10) & vbTab
s2 = s2 & oFil.Name & vbTab
s2 = s2 & formatnumber(oFil.Size, 0,-1,,-1) & " bytes" & vbTab
s2 = s2 & oFil.Path & vbTab
s2 = s2 & owner & " "
objOutputFile.WriteLine(s2 )
end if
End Sub
It works great up until it comes in contact with a certain folder/file apparently.
I thought at first it was due to the folder being named with a "!" but I don't believe that's it. Presumably this scans alphabetically? If so, we go through the following folders before it stops:
!!!!MEU Pricing folder
!!Save_Florida_2003
!Thomas O'Malley
The last entry is a Hack.MDB in !!Save_Florida_2003 before it stops and errors on:
(66,6) (null): 0x8004103A
VERY GRATEFUL FOR ANY AND ALL ASSISTANCE WITH THIS!!! : )
Code below:
==========================
Dim FSO, oFil, s2, objArgs, objItem
Dim computerName, owner
Dim objFileSystem, objOutputFile
Dim strOutputFile
Set FSO = CreateObject("Scripting.Fi
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper
Set objNetwork = Wscript.CreateObject("Wscr
computerName = objNetwork.ComputerName
strOutputFile = "e:\batch\" & computerName & "-db.lst"
Set objFileSystem = CreateObject("Scripting.fi
Set objOutputFile = objFileSystem.CreateTextFi
if fso.folderexists("g:\group
set f = fso.getfolder("g:\groups_1
elseif fso.folderexists("g:\group
set f = fso.getfolder("g:\groups")
end if
call searchall(f)
if fso.folderexists("h:\group
set f = fso.getfolder("h:\groups_2
elseif fso.folderexists("h:\group
set f = fso.getfolder("h:\groups")
end if
call searchall(f)
if fso.folderexists("i:\group
set f = fso.getfolder("i:\groups_3
elseif fso.folderexists("i:\group
set f = fso.getfolder("i:\groups")
end if
call searchall(f)
Sub SearchFolder(byRef objFolder)
Dim objFile, objSubFolder
if not objFolder.name = "System Volume Information" then
For Each objFile in objFolder.Files
Call SearchFile(objFile)
next 'objFile
end if
if not objFolder.name = "System Volume Information" then
For Each objSubFolder in objFolder.SubFolders
Call SearchFolder(objSubFolder)
Next 'objSubFolder
end if
End Sub
Sub SearchAll(byVal strFolder)
dim objFSO, objFolder
' Setup the FSO Object
Set objFSO = CreateObject("Scripting.Fi
' Get the root folder
Set objFolder = objFSO.GetFolder(strFolder
objOutputFile.WriteLine("S
Call SearchFolder(objFolder)
End Sub
Sub SearchFile(byVal oFil)
if right(oFil.name, 4) = ".mdb" then
' objOutputFile.WriteLine(oF
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecurity
For Each objItem in colItems
owner = objItem.AccountName
Next
' s2 = ""
s2 = Computername & vbTab & left(oFil.DateCreated, 10) & vbTab
s2 = s2 & left(oFil.DateLastAccessed
s2 = s2 & left(oFil.DateLastModified
s2 = s2 & oFil.Name & vbTab
s2 = s2 & formatnumber(oFil.Size, 0,-1,,-1) & " bytes" & vbTab
s2 = s2 & oFil.Path & vbTab
s2 = s2 & owner & " "
objOutputFile.WriteLine(s2
end if
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Arthur_Wood.
Presumably, I would test prior to this section, correct?
For Each objFile in objFolder.Files
---> objFile=replace(objFile,"' ","''")
Call SearchFile(objFile)
next 'objFile
But wouldn't that error out trying to find the file?
If the filename is currently Jim'sFile and I then change it with replace to Jim''sFile - it won't find that file...will it?
Presumably, I would test prior to this section, correct?
For Each objFile in objFolder.Files
---> objFile=replace(objFile,"'
Call SearchFile(objFile)
next 'objFile
But wouldn't that error out trying to find the file?
If the filename is currently Jim'sFile and I then change it with replace to Jim''sFile - it won't find that file...will it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great - I'll give that a shot - thanx!
ASKER
Okay, I'm a beginner no doubt...but...
Presumably somewhere inside the SearchFile routine is where i'd change this...
Sub SearchFile(byVal oFil)
but if I try
oFil.name=Replace(Ofil.nam e,"'","?")
It's stating file already exists... :(
Where should I replace the file name string? objFile perhaps?
Presumably somewhere inside the SearchFile routine is where i'd change this...
Sub SearchFile(byVal oFil)
but if I try
oFil.name=Replace(Ofil.nam
It's stating file already exists... :(
Where should I replace the file name string? objFile perhaps?
ASKER
Update...closer, but still no cigar.
here's wat I've discovered. Yes, it must be indeed with the ' character. I renamed it and it ran through nicely.
However - if I don't rename it (which would be impossible on all servers - not to mention customer complaints :)
it fails here:
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecurity Setting='" & oFil.path & "'}" & " WHERE AssocClass=Win32_LogicalFi leOwner ResultRole=Owner")
For Each objItem in colItems <----- errror points here
owner = objItem.AccountName
Next
So...I decided to use the replace string and it appears to 'work' - however, now it is not pulling back ANY ownership information... here's the revised line:
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecurity Setting='" & replace(oFil.path,"'","?") & "'}" & " WHERE AssocClass=Win32_LogicalFi leOwner ResultRole=Owner")
here's wat I've discovered. Yes, it must be indeed with the ' character. I renamed it and it ran through nicely.
However - if I don't rename it (which would be impossible on all servers - not to mention customer complaints :)
it fails here:
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecurity
For Each objItem in colItems <----- errror points here
owner = objItem.AccountName
Next
So...I decided to use the replace string and it appears to 'work' - however, now it is not pulling back ANY ownership information... here's the revised line:
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecurity
ASKER
Going to try to alter as I found here:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1007.mspx
Will post back shortly...
http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1007.mspx
Will post back shortly...
ASKER
Nah - still not it.
For now, I'll just use an
if instr(1,oFil.path,"'") then owner="" and skip the check owner WMI call.
I'll leave this open for a little longer - if someone has an answer - I'D LOVE to know it!!!
It's working on all the other files as expected. Thanx for your time!
For now, I'll just use an
if instr(1,oFil.path,"'") then owner="" and skip the check owner WMI call.
I'll leave this open for a little longer - if someone has an answer - I'D LOVE to know it!!!
It's working on all the other files as expected. Thanx for your time!
ASKER
http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1217.mspx seems to resolve it...I'll try it out and let you know!
ASKER
Well, 'yes' and 'no'. The answer is to escape the apostrophe with a preceding backslash (so ' becomes \').
But I have yet to get it to work properly and here is why I think so...
I pass objFile as an object here:
For Each objFile in objFolder.Files
Call SearchFile(objFile)
If I tried to use the replace function, well now I've no longer got an object, I've got a string, right? So, no more referencing objFile (or oFil) 'dot' anything (Path or Name).
So...I tried passing two seperate variables, strFileName and strFolderName - but was having trouble, and thought better of it.
Any ideas how to bypass my problem, please post. I'm still working on this. Thanx
But I have yet to get it to work properly and here is why I think so...
I pass objFile as an object here:
For Each objFile in objFolder.Files
Call SearchFile(objFile)
If I tried to use the replace function, well now I've no longer got an object, I've got a string, right? So, no more referencing objFile (or oFil) 'dot' anything (Path or Name).
So...I tried passing two seperate variables, strFileName and strFolderName - but was having trouble, and thought better of it.
Any ideas how to bypass my problem, please post. I'm still working on this. Thanx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
cool, glad you got it working. I only realised late last night after posting my comment that although it'd run, it wouldn't find anything. duh.
ASKER