Bat file to open webpage with parameters to local file - windows

Creating a bat file with:
start http://www.google.com/search?q=test
Does just what I would want it to do, it opens my default web browser (Chrome in my case) and browses to the URL http://www.google.com/search?q=test.
However, a bat file with:
start file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1
Only opens my default browser and browses to file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html
Note the lack of ?wbt=1. In order to fix this I've tried:
URL encoding the question mark
Running the start command parameters "window name" "file path in quotes"
Putting the file path in
variable and passing the variable to start
But none of those work. How can I get this to work?

I tested this and got the same result. I'm not really sure, but I guess this belongs to the question mark. The local file system of Windows can never have file names with ?, because this is a "wildcard" like *. I think it is possible that the file name is truncated there.
The following codes also doesn't work or produces only error messages:
start "file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1"
start file:///"C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1"

The best solution I've come up with so far is:
powershell -noprofile -command "[void][System.Diagnostics.Process]::Start('chrome', 'file:///C:/Users/d92495j/Desktop/OracleCDs/WebLogic/template.html?wbt=1')"
This solution has the batch file launch PowerShell and then use the .NET System.Diagnostics.Process.Start method to launch Chrome with the correct parameter. The only downside is that it makes a browser choice for me and I'd prefer it to use my default browser, but I can live with that. I'll accept another answer (that is not much more complex) that uses the default browser.

Related

How to write a regedit value that would take information from a url and send it to cmd?

my goal is to launch a .vnc file from html, i have now figured out how to open it directly via cmd.
C:\Program Files\TightVNC>start tvnviewer.exe -optionsfile=C:\Users\user\Desktop\Links\test.vnc
so this works, but now i need to figure out how to make a regedit so that i can make URL links for all the files saved on our intranet, ideally i would have just the file name as a variable in the URL and the rest be done by the regedit value, so that whenever a link in our html file is pressed, cmd is launched and executes the command and replacing the variable by the name of the file.
I imagine it like this customurl://testfile
and it should automatically launch my vnc application stated above, with the -optionsfile being at the same address as i specified, only the name would now be testfile.vnc.
edit: forgot to mention that i already do have a regedit entry for the custom url protocol and keys such as customurl>shell>open>command

Windows command+ Browser bookmark

Kindly help is there any command to access browser bookmark via command line and open the bookmarked URL's via command line or powershell or wmic.
Also is there any event in windows which tells when a bookmark was accessed.
Thanks in Advance.
Generally speaking, there is no event to let windows know that any browser executed or accessed a bookmark.
Normally the bookmarks are stored inside a file like "bookmarks.adr" or similar which contains all the information the browser has about the stored bookmarks (except thumbnail or favicon data). If you want to access the URLs and open them, you need to parse the bookmarks file and extract the URLs. Doing this on the commandline with batch only is tricky at least... unless you just need something simple like a findStr on http which would extract all those URLs beginning with http (check out findStr /? and type /? and try something like type bookmarks.adr | findStr http > urls.txt which needs to be processed further with a for loop maybe (check out for /? on the commandline).
PowerShell might get the job done more easily but I don't know about the specific format of the bookmarks file and the browser you target. The browsers have their own format and thus the parsing is different for each browser class (maybe it is more unified than I am aware of, since most browsers are based on Chromium nowadays and therefore certainly share the same bookmarks file format).
Hope this helps. Good Luck with your project :)

Passing arguments while launching program from browser

I am trying to launch an application (.exe) from my browser.
The specific app needs 4 arguments/parameters when launching, which are: firstname, lastname, id, info
Is there a way to add these arguments on the Internet Explorer address bar when i launch my program?
I mean something like this:
"myapp:// -firstname -lastname -id -info"
(I only managed to add those arguments straight to the windows registry, it worked that way. But thats no help... i need them to be inputted when launching the app )
I have added this to my windows registry:
[HKEY_CLASSES_ROOT\myapp]
#="URL:myprogram Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
#="\"C:\\myapp.exe\""
[HKEY_CLASSES_ROOT\myapp\shell]
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\vsa\shell\open\command]
#="\"C:\\myapp\" "%1"
Thanks for help already! I hope someone knows how to fix this... :)
ps. Im using windows 7 64 bit and Internet Explorer 10.
You cannot simply pass multiple command line arguments to your application (unless they're listed explicitly in the registry as you've shown).
Instead, you must code your application's executable so that it is able to process the Application Protocol URL string. So your code is invoked by the browser like so:
C:\apps\myapp.exe "myapp:myParam?myParam2&myParam3&myParam4"
The executable must be able to process this string and handle it appropriately. You must take care to avoid security holes in the parsing of this string, as ANY webpage could exploit a hole here to escape the browser sandbox and attack the user's system.
There's more information on Application Protocols in this post: http://blogs.msdn.com/b/ieinternals/archive/2011/07/14/url-protocols-application-protocols-and-asynchronous-pluggable-protocols-oh-my.aspx

How do I make Firefox open a file with an ampersand in the filename?

I've written some Ruby code to inspect ZIP-files as part of an internal company process. The way we usually launch this code is from a web browser. When you click to download the file, you select "open with" and specify the full path to a small batch file. This one-line batch file looks like this:
\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "%~dp0inspect.rb" %1
As far as I know, this technique is the only easy way to launch my Ruby code on a Windows machine which doesn't have Ruby installed, but does have access to the company internal filesystem.
I'm having a problem when the filename of the ZIP file contains an ampersand.
This works fine on IE and Chrome, where the above line gets "expanded" out to the following:
C:\WINNT\Profiles\matthew\Desktop>\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "\\mathworks\public\Matthew_Simoneau\sandbox\inspect\inspect.rb" "C:\WINNT\Profiles\matthew\Local Settings\Temporary Internet Files\Content.IE5\VNATJ3X0\park&park_paper_LMI_neuralN[1].zip"
On Firefox, however, everything after the ampersand in the filename gets dropped on the floor:
H:\>\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "\\mathworks\public\Matthew_Simoneau\sandbox\inspect\inspect.rb" C:\Temp\park
I've tried putting the %1 in quotes in the batch file, but that has no effect.
I suspect this is a bug in Firefox. I've searched the Firefox bug list, but didn't find anything.
Am I doing something wrong here? Is this a Firefox bug? If so, is there a way I can work around it? Is there a more robust way to launch my Ruby code from a web browser?
Update: I filed a bug report with Bugzilla#Mozilla, but there hasn't been a response yet.
Since you apparently have no control over the zip filenames, you could do the following in the Ruby code...
If the filename passed does not exist, look in the same folder for any file with the base passed filename followed by "&*.zip".
This will work for "park&park.zip" as long as there isn't also a zip file already in the folder named, say, "park&foo.zip".
If there is a real potential for filename collision (i.e., the zips aren't being cleaned off the user's machine and ampersands are common), the only other solution might be using a download manager plug-in in Firefox that has filename re-writing capability to fix any ampersands on the way down.
I've just tested something similar with Firefox 3.5.2 on Linux and it works well (i.e. shell script gets the correct path).
You should first try to use a script like that:
echo %1 > c:\temp\test.txt
(hope that's the right syntax, I didn't use cmd for a long time)
…and see if you get right path in that file. If the ampersand is stripped in that file too, and you're using the latest version of Firefox, that means you found bug specific to Windows platform and you should report it.
Use %24 for the & character. See the URL Encoding Table for other such problematic characters: http://webdesign.about.com/library/bl_url_encoding_table.htm
Encode your ampersand for best results...
&
As in
C:\WINNT\Profiles\matthew\Desktop>\\mathworks\public\Matthew_Simoneau\ruby-1.8.7-p72-i386-mswin32\bin\ruby.exe "\\mathworks\public\Matthew_Simoneau\sandbox\inspect\inspect.rb" "C:\WINNT\Profiles\matthew\Local Settings\Temporary Internet Files\Content.IE5\VNATJ3X0\park&park_paper_LMI_neuralN[1].zip"

how to let ruby call default browser to open localfile

In this question, I find that using system('start http://www.google.com') is OK. If the file is in local disk, though, using system('start file:///c:/temp/a.html') doesn't work. How do I have Ruby get the default browser to open a local file?
What do you get when you double click a .html file in Windows Explorer? If it isn't the browser then that is your problem. The 'start' keyword pushes the path through the ShellExecute function, for http:// URLs is knows to open that in a browser, if it is a file it depends on the extension of the file, if your system has .html pointing to notepad for example (because in the past you have set it to notepad) it is always going to open it in that program unless you go and specifically change it.
From a generic work around point of view there is not much you can do, if you can access the Windows registry under Ruby then you can query the HKEY_CLASSES_ROOT\http\shell\open\command default value which contains a command line for the current browser bound to the HTTP protocol, you could use that to construct a full path (replace the %1 with the URL string).

Resources