【发布时间】:2015-10-18 06:52:35
【问题描述】:
我正在构建一个 VBScript 来搜索和记录从主目录复制的文件的位置(重复)。
我目前有一个脚本可以递归搜索 C 驱动器并将所有文件位置记录到日志文件中。 (这并不优雅,但我仍在进行概念验证。)
然而,当我遍历文件系统时,我发现脚本甚至无法查看大量文件夹——Appdata、本地设置、我的视频、我的图片等。
因此,用户显然无法访问其中的一些,但用户对“我的文档”中的文件夹拥有所有权,所以我无法确定为什么我的脚本甚至无法读取它们的内容。用户是本地管理员。
我尝试通过将此 sn-p 添加到开头而不改变行为来以提升的权限运行脚本:
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, WScript.ScriptFullName & " /elevate", "", "runas", 1
WScript.Quit
End If
这是脚本中的一个显着功能,其中错误的行已注明(如果另一部分有帮助,请告诉我):
' 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
我有什么方法可以让这个脚本访问这些文件夹吗?计算机在域中,但我可以进行任何必要的修改(甚至是策略)。
【问题讨论】:
标签: recursion vbscript permissions filesystems file-permissions