?
Solved

CreateFileMapping in Vista service

Posted on 2007-04-10
7
Medium Priority
?
2,459 Views
Last Modified: 2013-12-03
I have Windows service which calls CreateFileMapping with some name. User mode client opens file mapping with the same name. This works in Windows XP, but in Vista client reports "File mapping with this name doesn't exist". If the same server runs as Console application and not as service, client opens file mapping successfully.
lpAttributes of CreatefileMapping is NULL. Maybe I need to fill it by some way in client and/or server? Since I don't have previous experience in Windows services and security, I need some direction and maybe some code to solve this problem.
Thanks.
0
Comment
Question by:AlexFM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Accepted Solution

by:
alexcohn earned 1600 total points
ID: 18883124
That's a correct guess. Look at the examples here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PageIndex=2&SiteID=1&PostID=1332473 
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 400 total points
ID: 18886983
You need to set the security so as to allow non-service binaries access.
Here's some example code for the service side:
                  SECURITY_DESCRIPTOR         sd = {0};
                  InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
                  SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);

                  SECURITY_ATTRIBUTES sa = {0};
                  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
                  sa.bInheritHandle = FALSE;
                  sa.lpSecurityDescriptor = &sd;

                  m_MapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, m_SizeOfBuffer, m_NameOfMyMapView);

By the way, this is NOT unique to Vista.
I had the same problem on Windows 2003 when using a service to create the memory map file.
0
 
LVL 30

Expert Comment

by:Axter
ID: 18887006
FYI:
In my example, I'm mapping memory, instead of a particular file.
If you're mapping a file, change the first argument in above example to the file name.
Example:
m_MapHandle = CreateFileMapping(MyFileName, &sa, PAGE_READWRITE, 0, m_SizeOfBuffer, m_NameOfMyMapView);
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 48

Author Comment

by:AlexFM
ID: 18887681
Adding "Global\" prefix to memory mapped file name solved the problem - one of ways I found following by alexcohn's link. Thank you.
Axter, please take a look at my next Windows security question, maybe you can help there.
0
 
LVL 11

Expert Comment

by:alexcohn
ID: 18887771
Alex, I first decided to write only about "Global\", but while looking for a confirmation I came accross the comprehensive discussion in the MSDN forum, and actually erased my original comment!
0
 
LVL 48

Author Comment

by:AlexFM
ID: 18887962
For reference, after adding Global\ prefix my original problem was solved. But when I changed sevice account from User to LocalSystem, access to file mapping was denied on client side. After applying Axter's code to server side  CreateFileMapping, the problem was solved.
0
 
LVL 11

Expert Comment

by:alexcohn
ID: 18888001
Consider the remark of efratian (http://forums.microsoft.com/MSDN/ShowPost.aspx?PageIndex=2&SiteID=1&PostID=1332473#847374) in the MSDN forum thread. He provided exactly the same code using SetSecurityDescriptorDacl(). He explains further, that if you want the user mode client to have write access to the shared resource, you need, in Vista, to set the integrity level, specified via the SACL.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question