Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CreateFileMapping in Vista service

Posted on 2007-04-10
7
Medium Priority
?
2,470 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

609 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