Windows Server 2012 VBScript gets permission denied deleting files

耗尽温柔 提交于 2019-12-11 10:36:03

问题


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.



来源:https://stackoverflow.com/questions/31297449/windows-server-2012-vbscript-gets-permission-denied-deleting-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!