I am building a VBScript to search for and record the locations of files that have been copied out of a home directory (duplicates).
I currently have a script that recursively searches the C drive and records all file locations to a log file. (This is not elegant, but I am still working on a proof of concept.)
As I iterate through the file system, however, I find that there are a great many folders the script cannot even view- Appdata, Local Settings, My Videos, My Pictures, etc.
So of these are obviously inaccessible to the user, but the user has ownership over the folders in My Documents, so I cannot determine why my script cannot even read their contents. The user is a local administrator.
I have tried running the script with elevated permissions by adding this snippet to the beginning with no change in behavior:
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, WScript.ScriptFullName & " /elevate", "", "runas", 1
WScript.Quit
End If
This is a salient Function in the script, with the line that errors out notated (please let me know if another portion would be of aid):
' Get list of ALL files recursively and record them in a text file
Function getAllFilesRecursively (specifiedFolder, logLocation)
If (Right(specifiedFolder,7)<>"AppData") And _
(Right(specifiedFolder,16)<>"Application Data") And _
(Right(specifiedFolder,7)<>"Cookies") And _
(Right(specifiedFolder,14)<>"Local Settings") Then
' Get list of files in current folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(specifiedFolder.Path)
Set colFiles = objFolder.Files
'This function writes to a specified log file, using the specified method
writeToFile specifiedFolder, logLocationTemp, "Append"
' For each file, perform a task
For Each objFile in colFiles '(<<<<<<<<<<<<<<<<<<<< permissions error)
' Compose the full path to the file
fullPath = specifiedFolder & "\" & objFile.name
'Save the path to a text file (a newline is automatically added)
writeToFile fullPath, logLocation, "Append"
Next
' For each folder, Recurse
For Each Subfolder in specifiedFolder.SubFolders
getAllFilesRecursively Subfolder, logLocation
Next
End If
End Function
Is there any way for me to allow this script access to these folders? The computer is on a domain but I can make whatever modifications necessary (even policies).