简体   繁体   English

在 windows 上更改权限后访问文件时出现间歇性“访问被拒绝”异常

[英]Getting intermittent "Access is Denied" exception when accessing a file after changing the permissions on windows

Getting intermittent "Access is Denied" while accessing a file after changing the permission using icacls on windows.在 windows 上使用 icacls 更改权限后访问文件时出现间歇性“访问被拒绝”。

Details: Please refer to the script which has been run as administrator.详情:请参考以管理员身份运行的脚本。

import os


for x in range(50):

    #this exe will check the existence of a file , is not present then copy the file and change the permission to ADMINISTRATOR/SYSTEM:F and BUILTIN/Users:(RX)

    file = 'C:\\Program Files\\***\\test.exe'
    retval = os.system('"' +  file +  '" -i')
    print("retVal : %d" %retval)

    #reset the permission of the same file and the parent folder

    os.system("icacls C:\\ProgramData\\***\\ParentFolder /reset /T /Q /C")
    os.system("icacls C:\\ProgramData\\***\\file.xml /grant *S-1-5-32-545:(W) /T /Q /C")

We got the answer – icacls was running asynchronously hence while the permissions were getting changed, and at the same time if we will try to access the file then windows was giving "Access denied".我们得到了答案——icacls 是异步运行的,因此当权限被更改时,同时如果我们尝试访问该文件,那么 windows 给出“访问被拒绝”。 Therefore, instead of using icacls we starting using windows os APIs like https://learn.microsoft.com/en-us/windows/win32/api/aclapi/nf-aclapi-setnamedsecurityinfoa因此,我们不再使用 icacls,而是开始使用 windows os API,例如https://learn.microsoft.com/en-us/windows/win32/api/aclapi/nf-aclapi-setnamedsecurityinfoa

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

相关问题 在Windows Azure上运行WCF服务时获取“拒绝访问”异常消息 - Getting 'Access is Denied' exception message when running WCF service on Windows Azure Windows中文件权限未更改,但拒绝访问错误 - files permission is not changing in windows getting error access is denied 在 Windows 上运行 Kafka,但获取日志文件夹的访问被拒绝异常 - Running Kafka on Windows but getting Access denied exception for logs folder 尝试从 C:\ProgramData 访问文件时出现“拒绝访问” - Getting 'Access Denied' when trying to access file from C:\ProgramData 找不到文件异常,访问被拒绝 - File not found exception, access is denied Python 更改 Windows 权限后找不到模块 - Python not finding modules after changing permissions on Windows 目录上的Windows权限:Mercurial - hg merge - “abort:access is denied” - Windows permissions on a directory: Mercurial - hg merge - “abort: access is denied” 在Windows 10中访问c:\\ Programdata中的文件时访问被拒绝 - Access denied while accessing files in c:\Programdata in Windows 10 具有Everyone = READ的Windows文件使访问被拒绝 - Windows file with Everyone=READ gives Access is denied 在C#/ Windows中模拟文件的“拒绝访问” - Simulating 'access denied' for a file in C# / Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM