开发者

Block a Processes Child Window?

开发者 https://www.devze.com 2023-03-07 07:55 出处:网络
I am launching a process in C# .NET that for some reason opens a message box when it is initially launched. What I need to do from my application is find some way to either prevent this message box fr

I am launching a process in C# .NET that for some reason opens a message box when it is initially launched. What I need to do from my application is find some way to either prevent this message box from ever being opened, or basically "click" the OK button on the message box from my code.

The message box is causing the process to hang when we run it as a service, so I now need to find some way to either prevent that box from ever opening or just close it (select OK) from my code.

I have been looking at some Win32 API samples, but I have never had to use it before and it looks a bit strange. Any suggestions would be great!

Edit

Here is a batch file that was supplied as a work around for the issue. However I would much prefer to have it running an executable if possible. The 开发者_如何学运维explanation was that using the -supw parameter (to set a password on the server) causes this message box to popup. This batch file is tested and works, but it requires you have a duplicated executable (murmur2.exe) created which is ghetto.

set /p VAR= < superadmin.txt
start murmur2.exe -supw %var%
ping 0.0.0.0 -n 3 > NUL
tskill murmur2
murmur.exe


PostMessage(FindWindow("#32770",*Title of the message box*),WM_CLOSE,NULL,NULL);

Since there might(with a very slim chance) be a same window opened with the same class name with the same title at the same time, this is not a fail proof way. However the alternatives are simply an overkill. If you really want to make it fail proof, you'll have to call EnumWindows to enumerate all top-level windows, then for each window, call GetWindowThreadProcessId and compare the window's process id with your launched process' id. If they are equal, you can then call GetClassName and GetWindowText to compare the class names(always "#32770" for common dialogs) and the title of the message box to verify that you're trying to close the right window. Once it's done, you can call PostMessage with WM_CLOSE using the hWnd that you found.

0

精彩评论

暂无评论...
验证码 换一张
取 消