I could not find any information about this. I am sure there is a term for this type of applications, but I have no idea where to look. That's why I decided to ask here.
So there are a few websites where you hover over a link or button it says something like application:xyz where application usually is the name application to run, and the xyz are the parameters or something.
An example is all the torrent links. If you hover over a link there it says
magnet:?somethingxxxxxxxxxxxx how can I bind my own custom application to a certain URL?
Let's say I have a C# application I call Musiclist. I want to make URLs like: musiclist:?song=hey123
And when I click it in my browser, it opens the application.
I really could not find anything about this with some examples, or how I pass those variables in with the :? in the link, so that's why I cannot provide any code examples.
This is what's called a protocol or a URI Scheme.
This is defined in the registry, so you'd have to add the correct values there:
HKEY_CLASSES_ROOT
<protocol>
(Default) = "URL:<protocol name>"
URL Protocol = ""
DefaultIcon
(Default) = "<path to your application>,<icon index>"
shell
open
command
(Default) = "<path to your application>" "%1"
In your case this could for example be:
HKEY_CLASSES_ROOT
musiclist
(Default) = "URL:Music list protocol"
URL Protocol = ""
DefaultIcon
(Default) = "C:\Program Files\Musiclist\musiclist.exe,0"
shell
open
command
(Default) = "C:\Program Files\Musiclist\musiclist.exe" "%1"
Everything after the colon (:) will be passed to your application as (a) Command Line Argument(s).
Related
I have an IE plugin which adds buttons in a page where there are pdf links and opens them in a specific application when clicked.
Lets say I need to open a xyz.pdf file in abc.exe application. abc is not the default application for file type .pdf.
In one machine the below works
Process p = Process.Start("pathtoabc.exe", "pathtoxyz.pdf");
In another machine it only works if I make abc.exe as the default app and then use the below
Process p = Process.Start("pathtoxyz.pdf");
Can you give me any pointers please? I also tried using ProcessStartInfo with no change
Updates:
I tried using the default Acrobat reader with an argument
Argument for processstartinfo looks like this "C:\PDF Files\Professional-Letters-Guide.pdf"
FileName = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
Result - Acrobat reader opens but with an error message "File not found". The is available in the path though.
Solved:
It was a space in the Foldername.. solved it by enclosing the filename with quotes "\""
Thank you all for the suggestions.. they helped me think it through.
Have you tried qualifying the Process.StartInfo.Arguments value with quotes and the full path to the file? What about the WorkingDirectory property? Also, the previous assertion regarding confirmation of the application being called supporting command line parameters is absolutely valid. You can be fooled into thinking that it does due to operating system file extension associations specific to a machine.
The second parameter of the Process.Start is passed to the application you are trying to start and it wont open the file using this application "pathtoabc.exe" unless the application "pathtoabc.exe" accepts the file name as a startup argument.
So you need to check if the application you are trying to use supports this kind of argument.
I'm writing code that will start a download from our company's ftp (ftp://...) but when using Process.Start("ftp://..."); Windows will prompt me for an app to open it with (I'm using Windows 10). If I use Process.Start("http://www.google.com"); it doesn't prompt. How do I avoid this prompt and just navigate the user to the ftp URL?
Windows knows what to do with a URL that starts with http: open the default web browser and browse to that URL. However, it doesn't natively know what to do with a URL that starts with ftp.
When you're using Process.Start, think of it like running a command from the "run" line in Windows. You usually need to specify an executable to run, and any additional information -- i.e. arguments to the executable -- occur after the path or executable name.
In this case, I'd say you just want to start Internet Explorer and provide it your URL as an argument:
var psi = new ProcessStartInfo(Environment.ExpandEnvironmentVariables(#"%ProgramFiles%\Internet Explorer\iexplore.exe"), url);
var proc = Process.Start(psi);
EDIT: to answer your question about using the default browser, see this SO answer about how to get the default browser's path:
I'm trying to launch a web page inside a vitual android device. The address of the page takes multiple querystring parameters. For some reason when passing the url in all parameters after the first & are missing (including the &).
I have a very simple C# WinForm app to test this with. I am using MadBee NuGet package to send the commands to the android VM.
When I send the command I see the url loaded but as I described, it is missing the parameters that come after he first &
Below is a snippet of the code I am calling:
command = "am start -a android.intent.action.VIEW -d http://w18299:8009/Assignment/manage?assigner=57072352&unitID=6443&secret=asdasdasdasdasd&assignee=57072352";
ConsoleOutputReceiver creciever = new ConsoleOutputReceiver();
device.ExecuteShellCommand(command, creciever);
Does anyone have any ideas as to why the parameters would not make it across to Android?
Your parameters "make it across to Android" just fine. What you failed to realize is that your command is getting parsed by the Android shell on the device side and & has a special meaning for it. To stop the shell from treating & as special symbol use quotes like this:
command = "am start -a android.intent.action.VIEW -d 'http://w18299:8009/Assignment/manage?assigner=57072352&unitID=6443&secret=asdasdasdasdasd&assignee=57072352'";
I am trying to open a contextual help file in c#.
When i specify no anchor, it works perfectly.
Process.Start("C:/Help/Help.htm")
But when i specify anchor, it does not open
Process.Start("C:/Help/Help.htm#_Toc342057538")
Internally it changes '#' to '%23' and the path becomes "c:\Help.htm%23_Toc342057538" which browser is unable to recognize.
Browser is successfully opening the path "c:\Help.htm#_Toc342057538"
How to stop this automatic conversion by Process.Start. The same behavior is observed, if i give the anchor label as another argument, or use Uri class.
EDIT
Same behavior is observed, when i enter the string in Window Run. Following command also convert # to %23, which browser cannot recognize.
chrome c:/Help.htm#_Toc342057538
On my Windows 7 system, both of the following open C:\Help\Help.htm in Internet Explorer and scroll to the _Toc342057538 anchor:
Process.Start("iexplore", "file://C:/Help/Help.htm#_Toc342057538");
Process.Start("iexplore", #"C:\Help\Help.htm#_Toc342057538");
For Firefox and Chrome, only the file protocol seems to work:
Process.Start("firefox", "file://C:/Help/Help.htm#_Toc342057538");
Process.Start("chrome", "file://C:/Help/Help.htm#_Toc342057538");
Try this out. I just did it myself and working in internet explorer
string s = "file:///D:/tmp/test.html%23test";
s = uri.UnescapeDataString(s);
Process.Start(s);
Please let me know if it is working or not for you.
I see a lot sample but i don't find the something good for my problem.
This problem is : I have a program made in c#. I use the clickonce UNC system.
With the shortcut on the desktop, there is no problem.
But I want for sepecific users, add parameters like :
\server...directories...\myapplication.application /a:XXX /b:xxxx
The on the program the Environment.GetCommandLineArgs() doesn't work i haven't arguments.
The other sample speak about URI, but i user UNC installation not a URI link !!
Someone have the same problem and found a solution ?
thanks
LittleJC
There is no way to do this with a ClickOnce application invoked via UNC path. The only way to pass anything like command line parameters to a ClickOnce application is via URL string query parameters, but that only works when invoking via URL, not UNC. (See Noyes: Smart Client Deployment with ClickOnce, chapter 8, first section.)