Solved

NT Services & MapViewOfFile handles

Posted on 1997-09-15
4
559 Views
Last Modified: 2013-12-03
Dear experts...

I have written an NTService that I need to 'talk to' from various other applications via a DLL, so my service creates a hidden window that anyone else can send messages to. This all works fine for simple commands that can return their data in 32 bits, but some of the functionality I need to offer requires the two way transfer of character strings.

So, I create and populate a file map in my DLL (using CreateFileMapping), and send a message to my service asking for its Process Id so that I can use DuplicateHandle() to pass the file map across. This works fine when I run the service in the debugger, and also if I run it just as an executable. But when I run it as a service, when the service tries to use MapViewOfFile() using the duplicated handle, it gets a null pointer and GetLastError returns 6  (ERROR_INVALID_HANDLE).

Is there anything strange about how Services run and in particular their process context that might cause this? Are there any other/better ways of achieving a similar result other than having a hidden window?

Any help or ideas much appreciated!

kfe
0
Comment
Question by:kfe
[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
  • 2
4 Comments
 

Author Comment

by:kfe
ID: 1406814
Edited text of question
0
 

Author Comment

by:kfe
ID: 1406815
I've looked further into this, and have discovered that it has nothing to do with file map handles, but that the problem happens in my DLL!

When I try to use duplicate handle I use OpenProcess() to get the handle of the Service's process. but this returns a NULL handle! and GetLastError() gives me 5 (Access denied).

My guess is that the Service Control Manager is creating the Service process with security on it such that my user application cannot "open" it. Can any 'NT Service guru' out there confirm this?

kfe
0
 
LVL 3

Accepted Solution

by:
vinniew earned 100 total points
ID: 1406816
You're right.  If you try to debug a service by right-clicking on the taskbar, you'll notice that the system may have put security on it.  This usually happens to me when the service is paused or not completely stopped.  The solution is to use the task manager to kill the child process, and try again after the service is stopped.

You can use Mutexes to communicate with a service, also.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1406817
Suggestion: Communicate using named pipes.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

631 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