简体   繁体   English

运行VBScript时权限被拒绝

[英]Permission Denied when running VBScript

I have a vbs script which captures file information and then exports it to a csv file. 我有一个vbs脚本,它捕获文件信息,然后将其导出到csv文件。 I need to run the script on main drives such as C:\\, E:\\, I:\\ and more, but each time I run for the main directory I get "Permission Denied" when I try to run it for a subfolder example C:\\Program Files it works fine. 我需要在主驱动器(例如C:\\,E:\\,I:\\等)上运行脚本,但是每次运行主目录时,尝试为子文件夹示例运行该脚本时,都会收到“权限被拒绝” C:\\ Program Files它可以正常工作。 I have tested this on different desktop machines and servers with full admin accounts and still get it. 我已经在具有完整管理员帐户的其他台式机和服务器上进行了测试,但仍然可以使用。

What could be the issue with this code. 此代码可能是什么问题。 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

Please advise and modify code if you know where the issue is. 如果您知道问题出在哪里,请提出建议并修改代码。

If it's a permissions problem I would strongly recommend Process Monitor from Sysinternals to diagnose it. 如果是权限问题,我强烈建议Sysinternals使用Process Monitor进行诊断。 You should be able to watch the cscript process (or whatever is executing your script) and find out what kind of permission problem you're having. 您应该能够监视cscript进程(或执行脚本的任何过程),并找出遇到的权限问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行查询时用户被拒绝访问 - User is denied access when running a query 尝试在用户桌面上创建文件时权限被拒绝 - Permission denied when trying to create file on users desktop 批量插入权限被拒绝-BLOB与FILESTREAM - BULK INSERT permission denied - BLOB vs FILESTREAM 使用MSScriptControl从UIAccess VB应用程序运行VBScript - Running VBScript from UIAccess VB app using MSScriptControl Adodb Recordset函数.MoveNext导致异常“ UPDATE权限被拒绝” - Adodb Recordset function .MoveNext Causes Exception “UPDATE permission was denied” 异常详细信息:System.Security.SecurityException:权限被拒绝 - Exception Details: System.Security.SecurityException: Permission denied 运行“System.Diagnostics.Process.Start()”时访问被拒绝 - Access is denied while running “System.Diagnostics.Process.Start()” 如何实现ASP.NET标识:数据库“master”中的CREATE DATABASE权限被拒绝 - How to implement ASP.NET identity: CREATE DATABASE permission denied in database 'master' 尝试模拟用户时拒绝访问 - Getting Access Denied when trying to impersonate user WinSCP 上传文件到远程 SFTP 错误:“无法创建远程文件 - 权限被拒绝” - WinSCP upload file to remote SFTP error: “Cannot create remote file – Permission denied”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM