Home > Net >  Windows service access process condition
Windows service access process condition

Time:10-02


As shown in figure, made a no response program interface, used to test, and then I use Windows service for the operating state of the program, the following code:
Process [] Process=Process. GetProcessesByName (" ThreadTest ");
Bool proType=process [0]. Responding;
ProType should return false, but always return true, what reason is this?

CodePudding user response:

If the process does not have a MainWindowHandle, this property returns true.

CodePudding user response:

The session 0 isolation leads to
Look at the next Process. The realization of the Responding
 
Public bool get_Responding ()
{
if (! Enclosing haveResponding)
{
IntPtr mainWindowHandle=this. MainWindowHandle;
If (mainWindowHandle==IntPtr. Zero)
{
This. Responding=true;
}
The else
{
IntPtr ptr2 will;
This. Responding=NativeMethods. SendMessageTimeout (new HandleRef (this, mainWindowHandle), 0, IntPtr. Zero, IntPtr. Zero, 2, 0 x1388, out ptr2 will)!=IntPtr. Zero;
}
}
Return this. Responding;
}

Your services and the program is not running in the same session, and the Process, is Responding to the target program sends a Windows test message, 5 seconds in response to return true, but the premise is that need to be able to achieve the target process right main window handle
There is a very simple solution, hang a global hook, task desktop applications (with window) to start you will receive a notice, have the right, the target program module to load your hook, you just need to make a simple communication on both sides, such as full name pipes, sockets, global event (here refers to the kernel, is not an ordinary events) in.net, Shared memory

CodePudding user response:

No response because blocked, the day after tomorrow is still in the response
  •  Tags:  
  • C#
  • Related