Page 1 of 1

press no on external msgbox with yesno option

Posted: 17 Sep 2019 07:54
by Userdosfx
i want press no button on external msgbox and close it
the msgbox is window not process
i want close it with batch file code

Re: press no on external msgbox with yesno option

Posted: 17 Sep 2019 10:46
by ShadowThief
You can't use batch to interact with GUIs.

Re: press no on external msgbox with yesno option

Posted: 19 Sep 2019 04:52
by misol101
If an external program is ok, you can try running cmdwiz from your script: viewtopic.php?t=7402

If the dialog box is visible and focused at the time you want to press it from the script, it's easy, just send an 'n' character (key codes at https://msdn.microsoft.com/en-us/librar ... 85%29.aspx):

Code: Select all

cmdwiz sendkey 0x4e p

If the window that owns the dialog is not on top, then we need to find it and show it before sending the key. Use "cmdwiz windowlist" for a list of windows and their processes. Let's say we found out that the process name was Photoshop.exe, we should be able to show the window/dialog with:

Code: Select all

cmdwiz showwindow top /n:Photoshop.exe
Unfortunately at this point the dialog box may not be focused/respond to key input. I have yet to find a reliable way to ensure this, but standard dialog boxes tend to pop up a the center of the screen, so a little hack to move the mouse to the center and click there might work. After this, we send the 'n' character:

Code: Select all

cmdwiz showwindow top /n:Photoshop.exe
cmdwiz getdisplaydim w
set /a X=%errorlevel%/2
cmdwiz getdisplaydim h
set /a Y=%errorlevel%/2-50
cmdwiz setmousecursorpos %X% %Y% l
cmdwiz sendkey 0x4e p

In case the dialog opens as a result of something you do earlier in the script, you may also have to include a delay before doing anything else to make sure the dialog has been opened. Use this for a 1 second delay:

Code: Select all

cmdwiz delay 1000

Re: press no on external msgbox with yesno option

Posted: 28 Sep 2019 15:37
by Szecska
There is a way, but its not pure batch. It uses a temporary vbs script:

Code: Select all

@echo off
echo ret=Msgbox("Continue?",4,"Terminated.") 'msgbox(title,type,headline)   Add 16 to type to show it as an error, 32 to question, 48 to warning, and 64 to information >%TEMP%\yn.vbs 
echo wscript.echo ret >>%TEMP%\yn.vbs
rem The return code for the 'No' button is 7.
rem Now we need to query the code from the vbs.
for /f %%i in ('cscript /nologo %TEMP%\yn.vbs') do (
if %%i==7 (
taskkill /im program.exe
rem taskkill without the /f switch just simulates an ALT+F4 keypress on the process
)
)
del %TEMP%\yn.vbs
If I undestood your problem well, this will help