![]() |
|
[.NET] Using Window's URI Scheme. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Using Window's URI Scheme. (/showthread.php?tid=4535351) |
Using Window's URI Scheme. - SubGenius - Nov 13, 2014 Hi, I am going to show you how get advantage of Window's URI scheme so you can easily start your application from a website or pass arguments to it. It's the same method that torrent clients use to open Magnet links, skype and Battlefield. Here is an example: ![]() Skills required: Basic Knowledge of vb.NET Know how to open the windows registry and how it works. Some HTML knowledge. Dificulty level: 3/10? So, let's start: First we have to create a key in the registry. Open the start menu -> type regedit Create: Code HKEY_CLASSES_ROOT -> yourcommand -> shell -> open -> commandCode "C:\yourappsdir\app.exe" "%1">Have a look Here on how to create Registry Keys with VB.net This is how the registry key should look like: ![]() As you probably understood the URI scheme requires an executable location. This means if your application is portable you should change the location of the registry each time you start your application. Next, the website files. Nothing special, some simple HTML tags and a javascript function: Code: PHP Code I have no idea of web programming, searching for sources on the web made it possible. Upload this to your webserver and you are ready to test it. Now the application: First, make your application single instance: Go to Project Properties -> Application -> check Make single instance application ![]() This will prevent your application from opening multiple times. Then for this tutorial just add a textbox into your main form, ![]() and this into the code: Code Imports Microsoft.VisualBasic.ApplicationServicesNext, Go to Project Properties -> Application -> View Application Events and add a new sub: Code Sub App_NextInstance(ByVal sender As Object, ByVal e As ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance![]() And you are done. If you haven't understand what's going on until now I will explain you: What we do is register a special(?) command into the registry that allows us to start and parse arguments to our application from websites, or other applications. You can also use CMD to do the same: example: ![]() More links: Download The Project Here: yet unavailable How to use command lines URI Scheme on MSDN How to create registry keys within vb apps * - Nikey646 - Nov 13, 2014 Just a heads up for anyone who plans on using this, it will only work if you have the MicroSoft.VisaulBasic namespace imported (Horrible practice, in any language other then VB), and won't work in WPF Based applications (It does not have the SingleInstance option you use) The alternative to this, is to use the same Registry with NamedPipeStreams (If using a language outside of VB), and Mutex (If using WPF). I've previously posted an example of both, using Threading to make sure reading the new arguments does not freeze the application. For anyone interested: hackforums.net/showthread.php?tid=4470491 Also, just a hint: The registry stuff should be done upon installation, not runtime. Besides the reliance on the Microsoft.VisualBasic namespace, good tutorial! * - Ajumma - Nov 13, 2014 This is pretty cool! I always wanted to run my game from my website kinda like other games out there, and now I can. * - SubGenius - Nov 13, 2014 (Nov 13, 2014 04:56 AM)Nikey646 Wrote: Just a heads up for anyone who plans on using this, it will only work if you have the MicroSoft.VisaulBasic namespace imported (Horrible practice, in any language other then VB), and won't work in WPF Based applications (It does not have the SingleInstance option you use) Nice addition. Yeah, I mentioned you could create the registry key during installation or first run. All I wanted to do in this tut is to pass the method and the concept. * - Earn - Nov 14, 2014 Great tutorial. Finally something unique that I haven't seen posted. Good work. * - Salty - Nov 14, 2014 Damn. Great tutorial, OP. Nice to see you contributing. Expect green apples from me, when I can. 🤝 |