【问题标题】:Permission Denied when running VBScript运行 VBScript 时权限被拒绝
【发布时间】:2010-02-19 14:02:12
【问题描述】:

我有一个 vbs 脚本,它捕获文件信息,然后将其导出到 csv 文件。我需要在 C:\、E:\、I:\ 等主驱动器上运行脚本,但是每次我为主目录运行时,当我尝试为子文件夹示例运行它时,我都会得到“权限被拒绝” C:\Program Files 它工作正常。我已经在具有完整管理员帐户的不同台式机和服务器上对此进行了测试,但仍然可以使用。

这段代码可能有什么问题。测试.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

如果您知道问题出在哪里,请建议并修改代码。

【问题讨论】:

标签: vb.net vbscript export


【解决方案1】:

如果是权限问题,我强烈推荐来自 Sysinternals 的Process Monitor 来诊断它。您应该能够观察 cscript 进程(或任何正在执行脚本的进程)并找出您遇到的权限问题。

【讨论】:

  • 我没有想到任何其他脚本的问题,并且看不到代码的问题所在。我认为因为它只指定搜索文件夹而不是主驱动器目录。错误似乎在第 50、3 行。
  • C:\script\test.vbs(50, 3) Microsoft VBScript 运行时错误:权限被拒绝
猜你喜欢
  • 2019-01-18
  • 2012-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-03
  • 1970-01-01
  • 2017-03-24
相关资源
最近更新 更多