Windows Server 2012 VBScript 获得拒绝删除文件的权限
Windows Server 2012 VBScript gets permission denied deleting files
我的服务器 (Windows Server 2012 r2) 上有一个与所有人共享的文件夹。我的所有用户每天都会上传一个纯文本库存文件。然后我有一个 vbscript,我计划在我的管理员凭据下 运行 读取这些文件后将其删除。但是,我在尝试删除或移动文件时遇到权限被拒绝的错误。
下面是一些失败的简单代码:
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
回显生成了一个正确的现有文件路径。所以我想我有权限问题?这是一个非常普通的 Server 2012 安装。
在权限已经允许访问的文件上出现 "permission denied" 错误通常意味着该文件(仍然)由 someone/something 打开。您可以使用 net file
进行远程连接检查,或使用 handle
进行本地进程检查。
我的服务器 (Windows Server 2012 r2) 上有一个与所有人共享的文件夹。我的所有用户每天都会上传一个纯文本库存文件。然后我有一个 vbscript,我计划在我的管理员凭据下 运行 读取这些文件后将其删除。但是,我在尝试删除或移动文件时遇到权限被拒绝的错误。
下面是一些失败的简单代码:
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
回显生成了一个正确的现有文件路径。所以我想我有权限问题?这是一个非常普通的 Server 2012 安装。
在权限已经允许访问的文件上出现 "permission denied" 错误通常意味着该文件(仍然)由 someone/something 打开。您可以使用 net file
进行远程连接检查,或使用 handle
进行本地进程检查。