Solved

CreateFileMapping in Vista service

Posted on 2007-04-10
7
2,444 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 400 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What are the big features of MVC5? 4 103
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 309
Add values of each row in an array 3 79
No module found pypyodbc, 3 53
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

739 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