Solved

CreateFileMapping in Vista service

Posted on 2007-04-10
7
2,406 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Accepted Solution

by:
alexcohn earned 400 total points
ID: 18883124
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 100 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now