CreateFile failed with 5

392 views Asked by At

I'm using win xp Professional x64 Edition and I'm trying to send message to Windows Message Service like using net send. I'm using mailslot:

LPCTSTR SlotName = TEXT("\\\\.\\mailslot\\messngr");

hFile = CreateFile(SlotName,
        GENERIC_WRITE | GENERIC_READ,
        FILE_SHARE_WRITE | FILE_SHARE_READ,
        (LPSECURITY_ATTRIBUTES)NULL, 
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL, 
        (HANDLE)NULL);

and after launching it, I got error 5 from GetLastError() in CreateFile. I don't know how to fix it. I gave all VM permission, I turned message service ofc, and I can open it to be notpad like others suggested in: CreateFile() Failed With GetLastError() = 5. I tried many flags, but it didn't change anything. Any guess?

1

There are 1 answers

0
J.Backus On

Like it says in the mailslot documentation, only the process that created the mailslot can read from it. Mailslots are one-way communication.

Remove the request for read access.