Nov 13, 2014 03:34 AM
(This post was last modified: Nov 13, 2014 03:37 AM by SubGenius.)
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:
![[Image: z8ot2mR.gif]](https://i.imgur.com/z8ot2mR.gif)
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:and change the default value of command into this:
You can create this key in setup or when the user starts the application for first time.
>Have a look Here on how to create Registry Keys with VB.net
This is how the registry key should look like:
![[Image: NP5jPhZ.png]](https://i.imgur.com/NP5jPhZ.png)
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:
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
![[Image: DbxRAKt.png]](https://i.imgur.com/DbxRAKt.png)
This will prevent your application from opening multiple times.
Then for this tutorial just add a textbox into your main form,
![[Image: KXNkdbB.png]](https://i.imgur.com/KXNkdbB.png)
and this into the code:
Next,
Go to Project Properties -> Application -> View Application Events
and add a new sub:
![[Image: iKuAOQ1.png]](https://i.imgur.com/iKuAOQ1.png)
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:
![[Image: aY8EaEO.png]](https://i.imgur.com/aY8EaEO.png)
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
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:
![[Image: z8ot2mR.gif]](https://i.imgur.com/z8ot2mR.gif)
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:
![[Image: NP5jPhZ.png]](https://i.imgur.com/NP5jPhZ.png)
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
<?php
<script type='text/javascript'>
function SendData(data) {
command = 'cCommand:'
redirecturl = command+data;
window.open(redirecturl,"_self")
}
</script>
<input type='text' name='text' id='text' />
<input type='button' value='Send Data' onclick='javascript:SendData("-text="+ document.getElementById("text").value);' />
<input type='button' value='Clear Textbox' onclick='javascript:SendData("-clear");' />
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
![[Image: DbxRAKt.png]](https://i.imgur.com/DbxRAKt.png)
This will prevent your application from opening multiple times.
Then for this tutorial just add a textbox into your main form,
![[Image: KXNkdbB.png]](https://i.imgur.com/KXNkdbB.png)
and this into the code:
Code
Imports Microsoft.VisualBasic.ApplicationServices
Public Class frmMain
'Check for Arguments after the application has started.
Public Sub app_NextInstance(ByVal sender As Object, ByVal e As ApplicationServices.StartupNextInstanceEventArgs)
CheckForArguments(cCollectionToArray(e.CommandLine))
End Sub
'Check for Arguements on start up.
Private Sub app_StartUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckForArguments(Environment.GetCommandLineArgs)
End Sub
'Here you can include whatever u like, it's simple to check for arguments and parse it's data.
Sub CheckForArguments(ByVal Arguments As String())
For Each Argument As String In Arguments
If Argument.Contains("-text=") Then
TextBox1.AppendText(Argument.Split("=")(1) & vbNewLine)
ElseIf Argument.Contains("-clear") Then
TextBox1.Clear()
End If
Next
End Sub
'Just a simple function that converts a collection of string into an array of strings, nothing to worry
Private Function cCollectionToArray(ByVal Collection As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As String()
Dim Array(Collection.Count - 1) As String
For i As Integer = 0 To (Collection.Count - 1)
Array(i) = Collection.Item(i)
Next
Return Array
End Function
End ClassNext,
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
frmMain.app_NextInstance(sender, e)
End Sub![[Image: iKuAOQ1.png]](https://i.imgur.com/iKuAOQ1.png)
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:
![[Image: aY8EaEO.png]](https://i.imgur.com/aY8EaEO.png)
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


