Solved

NT Services & MapViewOfFile handles

Posted on 1997-09-15
4
546 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

770 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