好的,這將會長時間與我在一起。
首先我將介紹這些要求。
然後我會告訴你如何滿足每一項要求
要求:「?」
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>
寫對我來說如果有什麼不行的話。我會幫你解決的。
祝你好運的朋友。