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
press no on external msgbox with yesno option
Moderator: DosItHelp
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: press no on external msgbox with yesno option
You can't use batch to interact with GUIs.
Re: press no on external msgbox with yesno option
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):
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:
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:
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:
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
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
There is a way, but its not pure batch. It uses a temporary vbs script:
If I undestood your problem well, this will help
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