首先,我将介绍要求。
然后我会告诉你如何满足每一个要求
要求:
- 创建一个小型命令行应用程序,它将目标应用程序路径作为参数并在“?”之后 将为目标应用程序接受参数。
- 创建一个包含自定义 URL 注册表信息的 .reg 文件。
- 使用自定义 URL 在您的网页上为应用程序创建一个链接。
让我们开始吧:
- 创建命令行应用程序: 步骤:
- 打开 Microsoft Visual Studio 并选择使用 Visual Basic 模板创建一个新的控制台应用程序。我们将其称为“MyLauncher”。
- 在项目属性 >> 应用程序中将目标框架版本设置为 .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>
如果有什么不起作用,请写信给我。我会帮你的。
祝朋友好运。