1

This is for a Windows 7 computer

I running a batch file (.bat) and want to configure it to open Internet Options and press the "Connections" tab and then press "OK".

So far I've got the following, which opens Internet Options:

inetcpl.cpl

I've been trying to follow the most upvoted answer at this link to do it, using the following, but it doesn't work or even open Internet Options:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run inetcpl.cpl
Community
  • 1
  • 1
maudulus
  • 10,627
  • 10
  • 78
  • 117

3 Answers3

3

Save this as .bat :

@if (@X)==(@Y) @end /* JScript comment
@echo off

    cscript //E:JScript //nologo "%~f0" 

exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */


var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("control inetcpl.cpl");
WshShell.AppActivate("Internet Properties");

WScript.Sleep(100);
WshShell.SendKeys("+{TAB}");
WScript.Sleep(100);

WScript.Echo("RIGHT keys.....");
WshShell.SendKeys("{RIGHT}");
WScript.Sleep(100);
WshShell.SendKeys("{RIGHT}");
WScript.Sleep(100);
WshShell.SendKeys("{RIGHT}");
WScript.Sleep(100);
WshShell.SendKeys("{RIGHT}");
WScript.Sleep(100);
//WshShell.SendKeys("{RIGHT}");

WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{ENTER}");
npocmaka
  • 55,367
  • 18
  • 148
  • 187
1

I have used the greatest answer of @npocmaka and answer on this question It has some improvements.

You can just save the following script as a bat file and run it.

@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" 
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */

var WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("rundll32.exe shell32.dll,Control_RunDLL inetcpl.cpl,,4");
WshShell.AppActivate("Internet Properties");

WScript.Sleep(100);
WshShell.SendKeys("{TAB}"); 
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{TAB}");
WScript.Sleep(100);
WshShell.SendKeys("{ENTER}");

I'd add as a comment to the @npocmaka answer, but I don't have enough reputation t oadd any comments here. I hope it helps somebody.

V.S.
  • 336
  • 1
  • 12
0

It's a string and has to be in quotes.

What I don't understand is why you pointlessly posted code without the error.

---------------------------
Windows Script Host
---------------------------
Script: C:\Users\User\Desktop\a.vbs
Line:   2
Char:   1
Error:  Object required: 'inetcpl'
Code:   800A01A8
Source:     Microsoft VBScript runtime error

---------------------------
OK   
---------------------------