Send windows message to a Windows Service

2020-05-27 09:26发布

Is there any tool to send (mimic) a windows message like 'WM_ENDSESSION' to a windows service?

OR

How can I send a windows message to a process using C#?

(I know only C#)

EDIT: Purpose: Basically I have to debug a windows service for fixing a bug that occurs only on system shut down.

7条回答
不美不萌又怎样
2楼-- · 2020-05-27 09:48

I don't know if this is a similar handle, I doubt it, but someone could let me know if it is, but you can get a Process handle, which means you could get the process using Process.GetProcessesByName("MyAppName");, althought don't rely on this as I don't think that it will get the handle that you are after. Just a suggestion.

Actually this method will work...you just need to access the 'MainWindowHandle' property of the process object. For Instance...

Process myProcess;
Int handle;
myProcess = Process.GetProcessesByName("MyAppName");
handle = myProcess.MainWindowHandle;
查看更多
登录 后发表回答