gpt4 book ai didi

c++ - CreateNamedPipe 导致 ERROR_ACCESS_DENIED?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:58:20 26 4
gpt4 key购买 nike

我需要为客户端和服务器(在同一主机)之间的通信创建命名管道,代码如下:

WCHAR wszPipeName[MAX_FILE_LENGTH];
swprintf_s(wszPipeName, MAX_FILE_LENGTH, L"\\\\.\\pipe\\TEST%d", uniqueID);
pipe = CreateNamedPipe(
wszPipeName, // name of the pipe
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT,
1,
MAX_MSG_SIZE,
MAX_MSG_SIZE , //inbound buffer
MAX_READ_DATA_TIMEOUT,
NULL // use default security attributes
);

处理程序返回的始终是 INVALID_HANDLE_VAULE,错误是 ERROR_ACCESS_DENIED。

这里有什么问题吗?它在 Windows 7/8 上运行。

谢谢

最佳答案

这是 Python 代码,但是它为本地用户设置了一个安全描述符并拒绝了远程:

dacl = ACL()

# Deny NT AUTHORITY\NETWORK SID
sid = CreateWellKnownSid(WinNetworkSid)
dacl.AddAccessDeniedAce(ACL_REVISION, GENERIC_ALL, sid)

# Allow current user SID
token = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY)
sid = GetTokenInformation(token, TokenUser)[0]
dacl.AddAccessAllowedAce(ACL_REVISION, GENERIC_READ | GENERIC_WRITE, sid)

security_descriptor = SECURITY_DESCRIPTOR()
security_descriptor.SetSecurityDescriptorDacl(True, dacl, False)

security_attributes = SECURITY_ATTRIBUTES()
security_attributes.SECURITY_DESCRIPTOR = security_descriptor

pipe = CreateNamedPipe(
<your other params here>
security_attributes
)

关于c++ - CreateNamedPipe 导致 ERROR_ACCESS_DENIED?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14313036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com