Open a Web Page in a Windows Batch FIle - windows

I have a batch file that does a bunch of things and at the end needs to open up a web browser to a page. Is there a way to, in essence, call ShellExecute on a http to open the web page?
Windows Command Prompt

You can use the start command to do much the same thing as ShellExecute. For example
start "" http://www.stackoverflow.com
This will launch whatever browser is the default browser, so won't necessarily launch Internet Explorer.

1.To run from the default browser, use
start http://www.stackoverflow.com
Please make sure that the appropriate browser is set as default at Control Panel-> default program :
2.To launch page from specific browser, one can use
start "iexplore.exe" http://www.stackoverflow.com
start "chrome.exe" http://www.stackoverflow.com
start "firefox.exe" http://www.stackoverflow.com

Unfortunately, the best method to approach this is to use Internet Explorer as it's a browser that is guaranteed to be on Windows based machines. This will also bring compatibility of other users which might have alternative browsers such as Firefox, Chrome, Opera..etc,
start "iexplore.exe" http://www.website.com

When you use the start command to a website it will use the default browser by default but if you want to use a specific browser then use start iexplorer.exe www.website.com
Also you cannot have http:// in the url.

hh.exe (help pages renderer) is capable of opening some simple webpages:
hh http://www.nissan.com
This will work even if browsing is blocked through:
HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer

start did not work for me.
I used:
firefox http://www.stackoverflow.com
or
chrome http://www.stackoverflow.com
Obviously not great for distributing it, but if you're using it for a specific machine, it should work fine.

Related

Open Chrome via PowerShell with parameter for SSO

we are using a PowerShell-script to start Chrome and open a specific website with some parameters like "host-rules" or "kiosk".
Unfortunately it is not possible to add the site to the Internet Explorer settings "local intranet" to make SSO working (because of the large infrastructure), but it is necessary to add the site there.
I tryed several searches via google, but I couldn't find what I'm looking for.
Who can help?
Thanks.
You can start chrome.exe using various commandline switches like
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk "https://yoursite.com"
A complete (?) list of switches can be found here

How to open a link in chrome from cmd (Windows) without bringing chrome window to foreground?

For example if I click on a link in vscode editor it does not interfere with what I am currently doing - opens it without making chrome window active.
I want to achieve the same from command line from windows using one of: cmd, msys bash, powershell.
There is a similar question answered but without foreground requirement.
Haven't tried it but with PowerShell you can try :
Start-Process -WindowStyle Hidden "chrome.exe" "www.google.com"
or
Start-Process -WindowStyle Minimized "chrome.exe" "www.google.com"
I see a solution here, however there seem to be no direct way to open links in chrome without bringing chrome window to foreground.
Use Chrome Remote Debugging Protocol. The browser has to be run with param --remote-debugging-port=9222. Actually, all instances of chrome have to be closed first. Then chrome can be controlled via this API. There is a client for it in most major languages, e.g. node:chrome-remote-interface.
I believe this is how also vscode does it, however they can do it even without remote-debugging-port parameter on the chrome instance.
So to complete the task in my original question, u need only to write some script that makes use of installed Debugging Protocol client of your choice.
Update: this also brings chrome to foreground (only if the window is hidden behind another window it doesn't). For definitive solution use chrome extension with tabs API (I am afraid this is necessary).
You can just Create one text file with .bat extension in windows OS.
Then you can write path where your Chrome is present and then you can write Chrome.exe and then give the link as argument which you want to open.
For Example,
cd C:\Program Files (x86)\Google\Chrome\Application
chrome.exe www.yahoo.com
I hope it will help you.

autoit open firefox and activate addon

I am new AutoIT. I see it has a lot of potential.
How can I write autoit code to open FireFox from specific location and inside it activate addon. Then the autoit code would navigate to a link?
I have some examples but it has been less then 1 hour since I started working on autoit.
My goal is to change FireFox profiles, run links inside each of those and close Firefox.exe after some time...
You can run the FireFox.exe to just bring the browser up (here is the documentation on that) and there is a FireFox AutoIt library available
You can use any of the below command to run your browser or any file
ShellExecute("filename")
or
Run( "The full path of the program f.ex- any exe or bat file")

From a shell script open a new tab in a specific instance of Firefox

I have a shell script that creates Firefox profiles and then uses them to open multiple instances of Firefox simultaneously. The problem is how can I open a URL in a particular instance of Firefox?
I have tried
firefox -CREATEPROFILE test
firefox -P test -no-remote
firefox -P test -url www.google.ie
But the last part which is trying to open the URL using the test profile does not work, it always opens in the default profile.
Is there any way to tell Firefox from the command line to open a URL using a particular profile?
Thanks.
EDIT: I am using Linux, I don't think its possible to do what I want to do from the command line (However, Firefox command-line options are not fully documented so it could be possible). One solution to my problem would be to use JavaScript to open the tabs once the browser has been executed. I think changing the default profile to the profile I want to open each time I want to load a new URL may work also. This will require changes to profiles.ini each time a new URL is loaded. I haven't tested this but it looks promising.
Yes this can be done, Modify your profiles.ini (/home/username/.mozilla/firefox/profiles.ini) to change the default profile each time you want to open a URL in a different profile.
I know this is a bit of a pain but it works and its the only way to do this. Now I can have multiple Firefox instances/profiles open simultaneously and still open new tabs in which ever instance I want from my shell script.
YAY!
Unfortunately Firefox only supports one remote profile at a time, so all your command lines have to remote into the same process. (Mozilla Suite for Linux supported a per-profile remote, but then again it didn't support the -profile flag.)
On the other hand if you know all the URL(s) that you want to load in advance, then you can simply pass all of them on the Firefox command line, concatenated with | characters (but quoted to stop the shell interpreting them). So for instance if you want to start a new instance of the test profile opening the page www.google.ie (only), use firefox -no-remote -P test -browser www.google.ie

How to launch an application from a browser?

Is it possible to launch an application from a browser? I am not talking about opening a file from a browser (like open a PDF with Adobe Reader), but rather opening a new (blank) instance of an application that is installed on the user's machine.
Hypothetical situation: User browses a website that lists computers that can be managed via RDP. He clicks on a link to 192.168.1.10, that link opens Microsoft RDP client (mstsc.exe) with that ip address already filled out.
I am talking strictly about Windows universe.
Is that thing even doable outside of ActiveX and IE?
Is it wise to attempt this in IE with ActiveX?
The correct method is to register your custom URL Protocol in windows registry as follows:
[HKEY_CLASSES_ROOT\customurl]
#="Description here"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\customurl\shell]
[HKEY_CLASSES_ROOT\customurl\shell\open]
[HKEY_CLASSES_ROOT\customurl\shell\open\command]
#="\"C:\\Path To Your EXE\\ExeName.exe\" \"%1\""
Once the above keys and values are added, from the web page, just call "customurl:\\parameter1=xxx&parameter2=xxx" . You will receive the entire url as the argument in exe, which you need to process inside your exe. Change 'customurl' with the text of your choice.
You can't really "launch an application" in the true sense. You can as you indicated ask the user to open a document (ie a PDF) and windows will attempt to use the default app for that file type. Many applications have a way to do this.
For example you can save RDP connections as a .rdp file. Putting a link on your site to something like this should allow the user to launch right into an RDP session:
Server 1
#AbhijithCR 's reply works well. To register the protocol via a .bat file, do something like this
set key=customurl
reg add HKCR\%key% /ve /d "URL:Description"
reg add HKCR\%key% /v "URL Protocol" /d ""
reg add HKCR\%key%\shell
reg add HKCR\%key%\shell\open
reg add HKCR\%key%\shell\open\command /ve /d ""c:\path to\your.exe" ""%%1"""
For me getting all the quotes and the double percent signs right was the tricky part.
Some applications launches themselves by protocols. like itunes with "itms://" links. I don't know however how you can register that with windows.
We use a sonicwall vpn. It launches a java applet that launches mstc with all the credentials setup. You really can't do this without a java applet or activex plugin.
Microsoft uses this technique itself on their small business server for getting inside the network. I wouldn't say it is a terrible idea, as long as platform independence isn't important.
You can use SilverLight to launch an application from the browser (this will work only on IE and Firefox, newer versions of chrome don't support this)
Example code here
I achieved the same thing using a local web server and PHP. I used a script containing shell_exec to launch an application locally.
Alternatively, you could do something like this:
Notepad

Resources