Home > Software engineering >  gpedit can't open vbscript,but cmd can,what's wrong
gpedit can't open vbscript,but cmd can,what's wrong

Time:07-12

my system is win10 here is my vbscript to open IE openIE.vbs

Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c start """" /max ""C:\\Program Files\\Internet Explorer\\iexplore.exe"" """ "https://www.google.com" """",vbhide

it works in cmd window

"C:\Program Files\chromeOpenIE\openIE.vbs"

but when I used gpedit to regist it in Register

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\chromeOpenIE]
@="IE"
"URL Protocol"=""
 
[HKEY_CLASSES_ROOT\chromeOpenIE\DefaultIcon]
@="iexplore.exe,1"
 
[HKEY_CLASSES_ROOT\chromeOpenIE\shell]
 
[HKEY_CLASSES_ROOT\chromeOpenIE\shell\open]
 
[HKEY_CLASSES_ROOT\chromeOpenIE\shell\open\command]
@="\"C:\\Program Files\\chromeOpenIE\\openIE.vbs\""

then use

chromeOpenIE://

it failed;

CodePudding user response:

You must run an Exe via your protocol handler. You cannot run a batch file or VBScript file directly. Use Cmd.exe to run batch files. Use WScript.exe or CScript.exe to run VBScript files.

Since you want to eliminate the Cmd flash, you should eliminate the use of a batch file and just run a VBScript IE launcher via WScript.exe. As noted in the comments, your IE launcher is not future proof. Use IE COM automation to launch IE. That works in Windows 11 and will continue to work in Windows 10 regardless of any updates to "disable" IE.

Note that it is bad practice to update HKEY_CLASSES_ROOT directly, as it represents a merged view of HKLM and HKCU entries. You should write your handler registry entries to HKCU, as shown below:

Windows Registry Editor Version 5.00
 
[HKEY_CURRENT_USER\Software\Classes\chromeOpenIE]
@="IE"
"URL Protocol"=""
 
[HKEY_CURRENT_USER\Software\Classes\chromeOpenIE\DefaultIcon]
@="iexplore.exe,1"
 
[HKEY_CURRENT_USER\Software\Classes\chromeOpenIE\shell]
 
[HKEY_CURRENT_USER\Software\Classes\chromeOpenIE\shell\open]
 
[HKEY_CURRENT_USER\Software\Classes\chromeOpenIE\shell\open\command]
@="WScript.exe \"C:\\Program Files\\chromeOpenIE\\openIE.vbs\""

And OpenIE.vbs should be this code:

Set oWSH = WScript.CreateObject("WScript.Shell")
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
oWSH.AppActivate "Internet Explorer"
oIE.Navigate "www.google.com"
oWSH.SendKeys "% "
WScript.Sleep 100
oWSH.SendKeys "x"
  • Related