Windows Server 2012 VBScript gets permission denie

2019-08-04 10:15发布

问题:

I have a folder on my server (Windows Server 2012 r2) that is shared with Everyone. All my users upload a plain text inventory file each day. I then have a vbscript that I scheduled to run under my Administrator credentials which deletes these files after reading them. However, I get permission denied errors when trying to delete or move the files.

Here is some simple code that fails:

Dim PathtoInventoryFiles
Dim myFSO
Dim myFile
Dim colFiles

PathtoInventoryFiles = "D:\Inventory$"
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = myFSO.GetFolder(PathtoInventoryFiles).Files

For Each myFile In colFiles
    wscript.echo myFile.path
    'Tried both of the following (only one at a time of course)
    myFSO.DeleteFile myFile.Path 'Permission denied
    myFile.Delete 'Permission denied
Next

Set myFSO = Nothing
Set colFiles = Nothing

The echo produces a correct path to a good and existing file. So I'm thinking I have a permissions issue? This is a pretty plain vanilla installation of Server 2012.

回答1:

Getting a "permission denied" error on a file where the permissions already allow access usually means that the file is (still) opened by someone/something. You can check that with net file for remote connections, or handle for local processes.