我有一个vbs脚本,它捕获文件信息,然后将它导出到csv文件。我需要在C:\,E:\,I:\等主驱动器上运行脚本,但是每次运行主目录时,我都会尝试运行子文件夹示例的“权限被拒绝” C:\ Program Files文件工作正常。我已经通过完整的管理员帐户在不同的台式机和服务器上测试过这些,并且仍然可以获得。权限在运行VBScript时被拒绝
这段代码有什么问题。 test.vbs
Option Explicit
Dim objFS, objFld
Dim objArgs
Dim strFolder, strDestFile, blnRecursiveSearch
Dim strLines()
Dim i
Dim strCsv
i = 0
' 'Get the commandline parameters
' Set objArgs = WScript.Arguments
' strFolder = objArgs(0)
' strDestFile = objArgs(1)
' blnRecursiveSearch = objArgs(2)
'###################################
'MAKE SURE THESE VALUES ARE CORRECT
'###################################
strFolder = "C:\"
strDestFile = "C:\Output.csv"
blnRecursiveSearch = True
'Create the FileSystemObject
Set objFS=CreateObject("Scripting.FileSystemObject")
'Get the directory you are working in
Set objFld = objFS.GetFolder(strFolder)
'Now get the file details
GetFileDetails objFld, blnRecursiveSearch
'Write the csv file
Set strCsv = objFS.CreateTextFile(strDestFile, True)
strCsv.Write Join(strLines, vbCrLf)
'Close and cleanup objects
strCsv.Close
Set strCsv = Nothing
Set objFld = Nothing
Set strFolder = Nothing
Set objArgs = Nothing
Private Sub GetFileDetails(fold, blnRecursive)
Dim fld, fil
dim strLine(5)
If blnRecursive Then
'Work through all the folders and subfolders
For Each fld In fold.SubFolders
GetFileDetails fld, True
Next
End If
'Now work on the files
For Each fil in fold.Files
strLine(0) = fil.Path
strLine(1) = fil.Type
strLine(2) = fil.Size
strLine(3) = fil.DateCreated
strLine(4) = fil.DateLastModified
strLine(5) = fil.DateLastAccessed
Redim Preserve strLines(i)
strLines(i) = Join(strLine, ",")
i = i + 1
Next
end sub
如果您知道问题所在,请告知并修改代码。
你用什么命令来运行该文件? – 2010-02-19 14:04:01
cscript.exe C:\ temp \ script \ test.vbs – MalsiaPro 2010-02-19 14:05:27
你会问多少次同样的问题? http://stackoverflow.com/questions/2279705/vbscript-issue-help-required http://stackoverflow.com/questions/2272317/vbs-script-help – Tester101 2010-02-19 14:46:16