0

I have a simple batch file that automates a task we do frequently. (End all internet explorer processes, open Control Panel>Internet Settings>Advanced>Reset IE). This is the code

@echo off
taskkill /F /IM iexplore.exe /T
timeout /t 2 /nobreak > NUL
rundll32.exe InetCpl.cpl,ResetIEtoDefaults

The problem is that this Windows function throws up a final approval window: enter image description here

Is there a native way in the batch file to simulate pressing the Reset button, or bypassing this and just executing it? *No third party software download.

Community
  • 1
  • 1
WakeDemons3
  • 127
  • 1
  • 7
  • 2
    To answer question. No. But if you used Vbscript you could accomplish your task. – Squashman Feb 22 '19 at 23:07
  • that question referred to executing a button press in a non-Windows application. i didn't see it as related because Windows can talk to Windows better than it can talk to Adobe. – WakeDemons3 Feb 22 '19 at 23:14

1 Answers1

1

Just use SendKeys() from Windows Script Host to simulate keyboard navigation. Generically, you could send Tab or Shift+Tab to move the focus to different window controls, or Spacebar to toggle a check box or activate a button. Or if the controls you want to activate are already assigned hotkeys (usually labeled with one letter underlined), just send Alt + whatever letter is underlined. In the case of this Internet Explorer dialog you're opening, Alt+P will toggle the check box, and Alt+R will activate the Reset button. See Microsoft's SendKeys() documentation for more details.

Here's a Batch + JScript hybrid example:

@if (@CodeSection == @Batch) @then
@echo off & setlocal
2>NUL taskkill /F /IM iexplore.exe /T
timeout /t 2 /nobreak > NUL
start "" rundll32.exe InetCpl.cpl,ResetIEtoDefaults

cscript /nologo /e:Jscript "%~f0"
goto :EOF

@end // end Batch / begin JScript hybrid code
var sh = WSH.CreateObject('Wscript.Shell');

sh.AppActivate("Reset Internet Explorer Settings");
sh.SendKeys("%p%r");

Here's another example, this time calling PowerShell from a .bat script:

@echo off & setlocal
2>NUL taskkill /F /IM iexplore.exe /T
timeout /t 2 /nobreak > NUL
start "" rundll32.exe InetCpl.cpl,ResetIEtoDefaults

powershell "$sh=new-object -COM Wscript.Shell;$sh.AppActivate('Reset Internet Explorer Settings');$sh.SendKeys('%p%r')"

Of course if there's a chance your scripts will be running on a Windows installation in a different language, you'd probably need to focus the reset window by its HWND rather than its title. That's a subject for another lesson, though.

rojo
  • 24,000
  • 5
  • 55
  • 101