好的,这将会长时间与我在一起。
首先我将介绍这些要求。
然后我会告诉你如何满足每一项要求
要求:“?”
1.创建一个将目标应用程序路径作为参数,后一个小命令行应用程序将为目标应用程序提供参数。
2.创建包含自定义URL注册表信息的.reg文件。
3.使用自定义URL为您的网页上的应用程序创建链接。
让我们开始吧:
1.创建命令行应用程序:
步骤:
A.打开Microsoft Visual Studio,并选择创建一个新的控制台应用程序使用Visual Basic的模板。我们将其称为“MyLauncher”。
B.在项目属性>>应用程序设置目标框架版本到.NET 2.0,以确保任何人都可以使用这个应用程序。
C.添加参照项目 - System.Windows.Forms的
D.覆盖所有默认的代码在你的Module1.vb文件到以下几点:
代码:
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.编译程序。并在本地进行测试后,将其放置在中央的某个位置,最好放在每个人都可以访问的网络驱动器上。
2.创建一个。包含下面的代码reg文件:
代码:
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.通过你的系统管理员分发中心分发了reg键或启动每台PC上的.reg文件。
B.用法:
mylauncher:AppYouWantToLaunchPathGoesHere ArgumentsGoHere
创建网页上的超链接:
代码:
<!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>
写对我来说如果有什么不行的话。我会帮你解决的。
祝你好运的朋友。