[英]Getting 'Access is Denied' exception message when running WCF service on Windows Azure
[英]Getting intermittent "Access is Denied" exception when accessing a file after changing the permissions on windows
在 windows 上使用 icacls 更改權限后訪問文件時出現間歇性“訪問被拒絕”。
詳情:請參考以管理員身份運行的腳本。
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")
我們得到了答案——icacls 是異步運行的,因此當權限被更改時,同時如果我們嘗試訪問該文件,那么 windows 給出“訪問被拒絕”。 因此,我們不再使用 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.