Open Internet Explorer from Chrome using a protocol handler (ie:url) - windows

I've followed these steps and it doesn't work correctly for me.
Custom protocol handler in chrome
Basically, I don't have a custom app. I just want to create an handler to open IE with a specific URL.
Here are my reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
#="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
#="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" \"%1\""
It's working but... when I'm opening ie:www.google.com from Chrome, it ask to open IE but it keeps the "ie:" in the opened URL... which generate a endless loop.
How can I fix that?
Thanks

Create a Protocol Handler
save this script as internet-explorer-protocol-handler.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
#="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
#="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\" %%myvar%% & exit /B"
Then run the script to install the keys in your registry. It will look like this:
Now links that use the ie: protocol will open in Internet Explorer.
Google
Demo Page

Here is a solution that should solve the problem with extended url's that contain parameters and special characters (&, % etc.)
Like this:
https://www.google.com/search?q=open-internet-explorer-from-chrome-using-a-protocol-handler&oq=open-internet-explorer-from-chrome-using-a-protocol-handler&aqs=chrome..69i57j69i60l3.1754j0j4&sourceid=chrome&ie=UTF-8
Replace the command in reg file with this:
powershell -windowstyle hidden -command "& {$Url = '%1' ; $Url = $Url -replace 'ie:',''; $IE=new-object -com internetexplorer.application ; $IE.navigate2($Url) ; $IE.visible=$true }"

After few tests, I move to another strategy.
I'm targetin an intermediate batch script instead.
And the batch split the protocol and the url, and open IE.
Here is the batch:
echo %1%
set var=%1
set var=%var:~4,-1%
Start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" %var%

Working registry:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"=""
#="URL:IE Protocol"
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
Some important notes:
You have to wrap %1 in double quotes. Otherwise url with multiple params like example.com?a=1&b=2 will be stripped to example.com?a=1, params after & will be ignored.
You have to remove the double quotes when calling iexplore. If you don't remove the double quotes and open multiple IE window from chrome, only the first IE window will get the correct URL. But removing quotes with command set url=%%url:\"=%% or set url=%%url:~1,-1%% doesn't work.
If you just can't make it to remove those quotes, add switches -nosessionmerging and -noframemerging to iexplore. These are command-line options to control "merging" behavior for IE.

The implementation of the registry will be more generic if you last line of the registry as
#="cmd /C set myvar=%1 & call set myvar=%%myvar:ie:=%% & call start /separate iexplore %%myvar%% & exit"
You wont need to create a custom script.
In case, the target URL can have more than 1 query params, you might face an issue that only the first param gets passed to IE (check the address bar on IE to validate).
In such a case, you can go for the following workaround ... simply create a new html file passing the target URL after encoding it and open this HTML on IE.
window.location = "ie:"+<URL to the above HTML>+"?path="+encodeURIComponent(<target URL>);
In the HTML file, just redirect to the decoded target URL
<html>
<head>
<title>
IE Redirect
</title>
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
vars[key] = value;
});
return vars;
}
function openURL(){
window.location.href=decodeURIComponent(getUrlVars()["path"]);
}
</script>
</head>
<body onload="openURL()">
</body>
</html>
The above worked perfectly in my application.

the following command will work for all query params to be passed:
cmd /C set myvar="%1" & call set myvar=%%myvar:ie:=%% & call start /separate "iexplore.exe" %%myvar%% & exit

the following command will work for all query params to be passed:
cmd /C set myvar="%1" & call set myvar=%%myvar:ie:=%% & call start
/separate "iexplore.exe" %%myvar%% & exit
We need to use the double quotes when a link had an ampersand in it and would not open in IE11 as anything after the ampersand was trimmed off.

Related

How to escape & ampersand in Custom protocol handler in Windows

I made a custom protocol handler following this link. The case is I need to open a link which can only be opened in IE and might contains several query parameters and should be opened in IE from our web app which is running on Chrome (this is really annoying). After many tries and fails, I managed to find the snippet to add entry to the windows registry hive and made .reg file and run:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\ie]
"URL Protocol"="\"\""
#="\"URL:IE Protocol\""
[HKEY_CURRENT_USER\Software\Classes\ie\DefaultIcon]
#="\"explorer.exe,1\""
[HKEY_CURRENT_USER\Software\Classes\ie\shell]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open]
[HKEY_CURRENT_USER\Software\Classes\ie\shell\open\command]
#="cmd /k set myvar=%1 & call set myvar=%%myvar:ie:=%% & call \"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\" %%myvar%% & exit /B"
It worked but the problem is if a link contains more than 1 query params, all but the first are omitted, I am sure this because of character encoding in windows command line:
e.g. some_example_url?query1=value1&query2=value2&query3=value3 is becoming some_example_url?query1=value1
I find this solution but it did not work either. How can I properly escape & character, so that it can be opened on IE with all query parameters. (as before mentioned link is triggered by web app running on Chrome)
EDIT: The code which triggers:
fileClicked(url) {
// url should be escaped with ^
const escapedUrl = url.replace(/&/gi, '^&');
const ie = document.createElement('a');
// ie: scheme => custom protocol handler
// host computer (windows) should add custom protocol to windows registry
ie.href = `ie:${escapedUrl}`;
ie.click();
}
EDIT 2
#muzafako fixed the script, just last line should be replaced like below:
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"
You don't need to decode query parameters at all. I've tried to find solution for this issue and saw this answer. Its works for me. just change command line to:
#="cmd /c set url=\"%1\" & call set url=%%url:ie:=%% & call start iexplore -nosessionmerging -noframemerging %%url%%"

Modifications of shortcut target path?

I need to change the shortcut target path from "google.com" to "yahoo.com" using the following VBScript:
Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\Wherever\Shortcut.lnk")
shortcut.TargetPath = "C:\Program Files(x86)\Internet Explorer\iexplore.exe" http://www.google.com"
shortcut.Save
When I'm running this from CMD
cscript file.vbs
I'm getting the following error:
excepted end of statement
Do I need to add <script language=script> or anything else?
This works for me:
Set sh = CreateObject("WScript.Shell")
Set shortcut = sh.CreateShortcut("C:\temp\Shortcut.lnk")
shortcut.TargetPath = "c:\temp"
shortcut.Save
Also, your script worked perfectly as-is after I created c:\wherever\.
Please post your error if it still doesn't work after ensuring the folder exists.
The syntax of your target path string is incorrect. You need to put double quotes around the entire string, plus you need to put escaped double quotes around the Internet Explorer path inside the string, because that path contains spaces. In VBScript you escape double quotes inside a string by doubling them.
Change this line:
shortcut.TargetPath = "C:\Program Files(x86)\Internet Explorer\iexplore.exe" http://www.google.com"
into this:
shortcut.TargetPath = """C:\Program Files(x86)\Internet Explorer\iexplore.exe"" http://www.google.com"
and the error will disappear.

Open a file with a .hta file [duplicate]

This question already has answers here:
Open a file with an HTA application
(2 answers)
Closed 2 years ago.
I'm making two HTA-applications. One is to install the other one. The code below is the VBScript in the installer HTA which does so that the computer recognises the .sjs extension (an extension which i've created and which has to do with the HTA being installed).
Public Sub Association(EXT, FileType, FileName, Icon)
Set b = CreateObject("wscript.shell")
b.regwrite "HKCR\" & EXT & "\", FileType
b.regwrite "HKCR\" & FileType & "\", "MY file"
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", Icon
b.regwrite "HKCR\" & FileType & "\shell\open\command\", FileName & " %L"
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName
End Sub
Association ".sjs", "SJS file", "C:\Users\Donald\my_app.hta","C:\Users\Donald\Desktop\my_icon.ico"
I would like it to do so that when I open a .sjs file, it opens the file C:\Users\Donald\my_app.hta, but like this it opens a dialog box where it says "C:\Users\Donald\Documents\file.sjs isn't a valid Win32 application". How can I do so that it does as I want?
Using On Error Resume Next without error check is irresponsible.
[Dim ] xxx As Object isn't valid VBScript. (Should be: [Dim ] xxx As yyy to emphasize that all typed declarations are illegal in VBScript)
Fix that and try again. Use ftype and assoc to check the result of your registry manipulation.
On second thought:
I think that a .HTA file should/must be opened with mshta.exe. (Should have an "explicitly" somewhere; see below)
Update:
I use isql.hta to work with ADO Databases interactively. Parameters and statements are stored in .isql text files. So to tried to mimic your problem with: "I want .isql files associated with the isql.hta application; proof of success: doubleclick on .isql file opens isql.hta". So
assoc .isql=ISQLFile
.isql=ISQLFile
ftype ISQLFile="X:\pathto\isql.hta" %*
ISQLFile="X:\pathto\isql.hta" %*
Doubleclick =>
---------------------------
M:\lib\amfvbs0703\amsinc.isql
---------------------------
M:\lib\amfvbs0703\amsinc.isql is not a valid Win32 application.
---------------------------
OK
---------------------------
M: is a mapped drive; so Windows thinks it's enemy country.
ftype ISQLFile=c:\WINDOWS\system32\mshta.exe "X:\pathto\isql.hta" %*
ISQLFile=c:\WINDOWS\system32\mshta.exe "X:\pathto\isql.hta" %*
Doubleclick => SUCCESS

How to Clear Firefox Cache and Cookies from .VBS or Bat

Hello I want to clear Firefox cookies + cache from .vbs script or bat , i already have tried ccleaner /auto but the thing is it needs browser to be closed for clearing cache and cookies else it skips it , i would like to clear cookies and cache without closing the browser from either .vbs script or .bat script can you please give the code or recommend any other method ?
thanks
Enduros answer might help,however here is a short way of doing it if you have ccleaner installed you can call the ccleaner comaandline ccsetup.exe /S or use other various parameter options to do whatever specific task you might be interested here is a link to there comandline options ccleaner commandline parameters you would also use the folling sniplet
#include <File.au3>
Dim $sPath = #AppDataDir & '\Mozilla\Firefox\Profiles'
Dim $arr = _FileListToArray($sPath, '*.default', 2)
If IsArray($arr) Then
For $i = 1 To $arr[0]
FileDelete($sPath & "\" & $arr[$i] & "\cookies.sqlite")
Next
EndIf

Printing a web page from Windows Batch

Is it possible to use a windows batch script to open a web page and print its contents to your default printer? Something simple as this:
#echo off
start /d IEXPLORE.EXE www.google.com
and now I want to send that page to the printer. But I am not sure of the syntax nor was I able to find anything specific or helpful on the web.
Does anyone know if it's possible to print a web page using a windows batch command?
Not from an iexplore switch, but vbscript will work:
Const PRINT = 6
Const DONTPROMPTUSER = 2
Const BUSY=4
Dim oIExplorer
Set oIExplorer = CreateObject("InternetExplorer.Application")
oIExplorer.Navigate "http://www.stackoverflow.com/"
oIExplorer.Visible = 1
Do while oIExplorer.ReadyState <> BUSY
wscript.sleep 1000
Loop
oIExplorer.ExecWB PRINT, DONTPROMPTUSER

Resources