First I will present the requirements.
Then I will show you how to meet each of the requirements
Requirements:
- Create a small command line application that will take the target app path as parameter and after "?" will take arguments for the target application.
- Create a .reg file containing Custom URL registry information.
- Create a link for an application on your webpage with the Custom URL.
Let's get started:
- Creating the command line application:
Steps:
- Open Microsoft Visual Studio and choose to create a new Console Application with Visual Basic template. We'll call it "MyLauncher".
- In project properties >> Application set target framework version to .NET 2.0 to make sure anyone will be able to use this app.
C. Add reference to project - System.Windows.Forms
D. Overwrite all the default code in your Module1.vb file to the following:
Code:
Imports System.IO
Imports System.Threading
Imports System
Imports System.Windows.Forms
Module Module1
Dim array As String()
Sub Main()
Dim origCommand As String = ""
Dim sCommand As String = Command().ToString
If String.IsNullOrEmpty(sCommand) Then
Application.Exit()
End If
origCommand = sCommand
origCommand = origCommand.Substring(origCommand.IndexOf(":") + 1)
origCommand = origCommand.Split("""")(0)
execProgram(origCommand)
End Sub
Private Sub execProgram(ByVal sComm As String)
Try
Dim myPath As String = Nothing
Dim MyArgs As String = Nothing
Dim hasArgs As Boolean
If sComm.Contains("""") Then
sComm = sComm.Replace("""", "").Trim()
End If
If sComm.EndsWith("?") Or sComm.Contains("?") Then
hasArgs = True
MyArgs = sComm.Substring(sComm.IndexOf("?") + 1)
myPath = sComm.Substring(0, sComm.IndexOf("?"))
Else
myPath = sComm
End If
If hasArgs Then
startProg(myPath, MyArgs)
Else
startProg(myPath)
End If
Catch ex As Exception
Dim errMsg As String = sComm & vbCrLf & vbCrLf & "The program you are trying to launch was not found on the local computer" & vbCrLf & vbCrLf & vbCrLf &
"Possible solutions:" & vbCrLf & vbCrLf &
"If the program doesn;t exist on the computer, please install it. " & vbCrLf & vbCrLf &
"If you did install the program, please make sure you used the provided default path for istallation. " & vbCrLf & vbCrLf &
"If none of the avove is relevant, please call support" & vbCrLf & vbCrLf
If ex.Message.Contains("The system cannot find the file specified") Then
MessageBox.Show(errMsg, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
Else
MessageBox.Show(ex.Message, "Default Error", MessageBoxButtons.OK)
End If
End Try
End Sub
Private Sub startProg(myPath As String, Optional MyArgs As String = "")
Try
Dim proc As Process
If Not String.IsNullOrEmpty(MyArgs) Then
proc = New Process()
proc.EnableRaisingEvents = False
proc.StartInfo.FileName = myPath
proc.StartInfo.Arguments = MyArgs
proc.Start()
Else
proc = New Process()
proc.EnableRaisingEvents = False
proc.StartInfo.FileName = myPath
proc.Start()
End If
Catch ex As Exception
End Try
End Sub
End Module
E. Compile the program and after testing it locally, put it somewhere central, preferably on a network drive that everyone has access to.
2. Create a .reg file containing the following code:
Code:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\mylauncher]
"URL Protocol"="\"\""
@="\"URL: mylauncher Protocol\""
[HKEY_CLASSES_ROOT\mylauncher\shell]
[HKEY_CLASSES_ROOT\mylauncher\shell\open]
[HKEY_CLASSES_ROOT\mylauncher\shell\open\Command]
;example path to the launcher is presented below. Put your own and mind the escape characters that are required.
@="\"\\\\nt_sever1\\Tools\\Launcher\\BIN\\mylauncher.exe\" \"%1\""
A. Distribute the reg key through your sysadmin central distribution or launch the .reg file on every PC.
B. Usage:
mylauncher:AppYouWantToLaunchPathGoesHere?ArgumentsGoHere
Create a hyperlink on your webpage:
Code:
<!doctype html>
<html>
<head>
</head>
<body>
<div class="test-container">
<a href='mylauncher:C:\Program Files\IBM\Client Access\Emulator\pcsfe.exe?U=MyUserName' >TEST</a>
</div>
</body>
</html>
Write to me if something doesn't work. I'll help you out.
Best of luck friend.