使用 _WinAPI_CreateFileMapping()
我想让同一台机器上的不同用户通过 _WinAPI_OpenFileMapping()
接收消息。当我尝试打开文件映射时收到错误消息(无效句柄错误 #6
),这可能是安全设置的原因。
我找到了 this post关于文件映射和允许跨用户访问。解决方案是创建一个 NULL 安全标识符(不传递 NULL,而是传递一个有效的安全标识符,包含 NULL):
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.NullSid, null);
如何在 AutoIt 中创建它并将其传递给 _WinAPI_CreateFileMapping()
?
发送端脚本(以本地用户身份运行):
Local $sid = _Security__StringSidToSid("S-1-0") ; also tried S-1-1
$hMapping = _WinAPI_CreateFileMapping(-1, 2048, 'MyFileMapping',0x0004,$sid) ;it seems to accept the sid
DllStructSetData($tData, 1, "IDL") ; if($hMapping) send the message...
接收服务脚本(以系统账户运行):
$hMapping = _WinAPI_OpenFileMapping('MyFileMapping')
还尝试通过只读。 0x0004
返回 0x0000
文件句柄/0
错误 0
扩展。一旦出现 1305
错误代码(无法复制)。
; if($hMapping) ... this is how I am trying to receive the message:
$pAddress = _WinAPI_MapViewOfFile($hMapping)
$tData = DllStructCreate('wchar[1024]', $pAddress)
$Text = DllStructGetData($tData, 1)
DllStructSetData($tData, 1, '')
最佳答案
尝试使用 S-1-0-0
而不是 S-1-0
关于winapi - 创建 tagSECURITY_ATTRIBUTES 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22919518/