我會爲程序註冊一個擴展名。你知道,當你敲擊一個xls文件時,它會以xls文件的url作爲參數,並且如果你敲擊一個播放列表文件,它會啓動你的mediaplayer。
您可以註冊(.exe)「.fro」文件的擴展名,該擴展名以.fro文件作爲參數打開您的程序。
如果你的程序已經在運行,它會得到參數,否則它啓動程序並傳遞參數。您的程序將讀取該文件並按照文件中的命令進行操作。例如,如果您的網絡應用程序中有一個鏈接應該讓您的winform程序打開一個客戶並顯示客戶詳細信息,那麼您可以讓您的Web應用程序有一個鏈接<a href="opencustomer.fro">Open customer</a>
,文件opencustomer .fro可以是動態創建的或靜態的。
註冊文件擴展名「.fro」打開您的.Net程序。 (示例如下)
使網站創建帶有命令的.fro文件。
按照本教程(http://visualstudiomagazine.com/articles/2007/11/01/simplify-application-instancing.aspx)將您的.Net程序轉換爲單實例應用程序。因此,如果第二個實例啓動,它將通過命名管道將命令$發送給第一個實例。
讓您的.Net程序下載.fro文件並解釋文件中的命令。這可能很簡單,只需包含一個打開的客戶編號即可。
我發現這個vb。有關注冊文件類型淨例如,它不應該是很難轉換或它的谷歌C#-version:http://bytes.com/topic/net/answers/519230-vb-net-associate-file-program
Public Class Example
Public Sub RegisterType()
Dim fileReg As New FileTypeRegistrar
With fileReg
.FullPath = Path_To_Executable
.FileExtension = Extension_To_Register
.ContentType = "application/" & Your_Description
.IconIndex = Icon_Index_In_Application
.IconPath = Path_To_Executable
.ProperName = Name_Of_Executable
.CreateType()
End With
End Sub
End Class
Public Class FileTypeRegistrar
#Region "Properties & Property Variables"
Private _ProperName As String
Public Property ProperName() As String
Get
Return _ProperName
End Get
Set(ByVal Value As String)
_ProperName = Value
End Set
End Property
Private _ContentType As String
Public Property ContentType() As String
Get
Return _ContentType
End Get
Set(ByVal Value As String)
_ContentType = Value
End Set
End Property
Private _FullPath As String
Public Property FullPath() As String
Get
Return _FullPath
End Get
Set(ByVal Value As String)
_FullPath = Value
End Set
End Property
Private _FileExtension As String
Public Property FileExtension() As String
Get
Return _FileExtension
End Get
Set(ByVal Value As String)
_FileExtension = Value.Replace(".", "")
End Set
End Property
Private _IconPath As String
Public Property IconPath() As String
Get
Return _IconPath
End Get
Set(ByVal Value As String)
_IconPath = Value
End Set
End Property
Private _IconIndex As Integer
Public Property IconIndex() As Integer
Get
Return _IconIndex
End Get
Set(ByVal Value As Integer)
_IconIndex = Value
End Set
End Property
#End Region
#Region "Public Methods"
Public Sub CreateType()
Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
Dim Ext As String = "." & FileExtension.ToLower
Dim extKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(Ext)
extKey.SetValue("", fileName)
extKey.SetValue("Content Type", ContentType)
extKey.Close()
Dim mainKey As RegistryKey = Registry.ClassesRoot.CreateSubKey(fileName)
Dim defIconKey As RegistryKey = mainKey.CreateSubKey("DefaultIcon")
defIconKey.SetValue("", IconPath & ", " & IconIndex)
defIconKey.Close()
Dim shellKey As RegistryKey = mainKey.CreateSubKey("shell")
Dim OpenKey As RegistryKey = shellKey.CreateSubKey("Open")
Dim cmdKey As RegistryKey = OpenKey.CreateSubKey("command")
cmdKey.SetValue("", """" & FullPath & " %1""")
cmdKey.Close()
OpenKey.Close()
shellKey.Close()
mainKey.Close()
End Sub
Public Sub DeleteType()
Dim fileName As String = Path.GetFileNameWithoutExtension(FullPath)
Dim Ext As String = "." & FileExtension.ToLower
Registry.ClassesRoot.DeleteSubKey(Ext)
Registry.ClassesRoot.DeleteSubKey(fileName)
End Sub
#End Region
End Class
是否有多個用戶使用您的Windows應用程序?如果是這樣,你將需要一個集中的服務來將你的命令分發給每個客戶端的Windows應用程序。 – 2009-08-31 01:45:54