Hi Paul,
Thanks for your feedback.
Service is a normal process, its only difference between other processes
are the window station(logon session) boundary. GUI messages/hooks can not
be used across window station boundary. So the communication between
service process and the SCP(Service Control Program) process can be any IPC
technologies except "Windows Message".
In Win32 world, I normally use named pipe for the IPC channel. However,
since named pipe is not encapsulated in .Net, the 2 recommended ways for
IPC in .Net are .Net remoting and socket. The 2 articles demonstrate these
2 technologies using in Windows Service:
"A TCP/IP Server written in C#"
http://www.codeproject.com/cs/internet/tcpserverall.asp
"How To Host .NET Remoting Objects In Windows Service Application"
http://www.codeproject.com/Purgatory/winservicehost.asp
Windows provided limited set of functions for cross-processes accessing,
they are WriteProcessMemory, CreateRemoteThread, VirtualAllocEx, etc...
Other Win32 API functions will only function in current process. More
specificly, Windows console APIs GetStdHandle, CreateFile,
CreateConsoleScreenBuffer and SetStdHandle to manipulate the console
standard output/input. However, all these APIs will take effect in a single
process and can not be used for another process, below article provided
more information regarding console handles:
"Console Handles"
http://windowssdk.msdn.microsoft.com/en-us/library/ms682075(VS.80).aspx
The reason that child process can be redirected standard output/input is
that the parent process passed the redirected pipe handles in CreateProcess
API's STARTUPINFO structure. CreateProcess API internally will help to
redirect the child process's standard output/input. Without child/parent
processes relation, we can not get the help of CreateProcess, and Windows
did not provide other documented way to redirect another process's standard
output/input.
If you really wanted to get this task done, my thought is injecting another
dll into the remote process. In the DllMain of this dll, your code is
executing in that process space now, you can call SetStdHandle API to
redirect the remote process's standard output/input. This is a pure Win32
cross process hijacking technology which can not be done in .Net. I mean,
the injected dll must be written with unmanaged C/C++ code, can not be the
..Net assembly.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.