Scott Sz
Scott Sz

Reputation: 3998

Create tagSECURITY_ATTRIBUTES object

Using _WinAPI_CreateFileMapping() I want to enable a different user on the same machine to receive messages via _WinAPI_OpenFileMapping(). I am receiving errors when I try to open the file mapping (invalid handle error #6), because of the security settings maybe.

I found this post about file mappings and allowing cross user access. The solution was to create a NULL security identifier (not passing NULL, but passing a valid security identifier, containing NULL):

SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.NullSid, null);

How do I create this in AutoIt and pass it to _WinAPI_CreateFileMapping()?

Sending side script (running as local user):

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...

Receiving service script (running as system account):

$hMapping = _WinAPI_OpenFileMapping('MyFileMapping')

Also tried passing read-only. 0x0004 returns 0x0000 file handle / 0 error 0 extended. Once a 1305 error code (can't duplicate that).

;  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, '')

Upvotes: 3

Views: 239

Answers (1)

Jiyan Akgül
Jiyan Akgül

Reputation: 161

Try S-1-0-0 instead of S-1-0

Source

Upvotes: 0

Related Questions