In Visual Basic .Net Windows Forms Application, These steps must be done at first:
1- Open Project Properties(‘Project’ Menu-> Properties)
2- Choose ‘Application’ Tab-page.
3- Check on ‘Make single instance Application’ Option.
4- Click on the ‘View Application Events’ to View Application Events Module code.
https://barnamenevis.org/attachment.php?attachmentid=154139&d=1667144883
Then...
Choose ‘StartupNextInstance’ Event of Application, Then put this code(for e.x.) :
Partial Friend Class MyApplication
Dim ci As New Customer
Private Sub MyApplication_StartupNextInstance(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupN extInstanceEventArgs) Handles Me.StartupNextInstance
Dim Params() As String = e.CommandLine.ToArray
Dim Command(-1) As String
For i = 0 To Params.Length - 1
Command = Params(i).Split(":")
Select Case Command(0).ToLower
Case "/n", "/name" : ci.Name = Command(1)
Case "/f", "/family" : ci.Family = Command(1)
Case "/b", "/birthday" : ci.Birthday = Command(1)
Case "/m", "/mobile" : ci.Mobile = Command(1)
Case "/ph", "/phone" : ci.Phone = Command(1)
Case "/i", "/image" : ci.Image = Command(1)
End Select
Next
My.Forms.Form1.SetInfo(ci)
End Sub
End Class
This is the ‘Customer Class’ Code used in above Statements:
Public Class Customer
Private NameValue As String
Public Property Name() As String
Get
Return NameValue
End Get
Set(ByVal value As String)
NameValue = value
End Set
End Property
Private FamilyValue As String
Public Property Family() As String
Get
Return FamilyValue
End Get
Set(ByVal value As String)
FamilyValue = value
End Set
End Property
Private BirthdayValue As String
Public Property Birthday() As String
Get
Return BirthdayValue
End Get
Set(ByVal value As String)
BirthdayValue = value
End Set
End Property
Private MobileValue As String
Public Property Mobile() As String
Get
Return MobileValue
End Get
Set(ByVal value As String)
MobileValue = value
End Set
End Property
Private PhoneValue As String
Public Property Phone() As String
Get
Return PhoneValue
End Get
Set(ByVal value As String)
PhoneValue = value
End Set
End Property
Private ImageValue As String
Public Property Image() As String
Get
Return ImageValue
End Get
Set(ByVal value As String)
ImageValue = value
End Set
End Property End Class
Now for send any parameter as known parameter in Application ‘StartupNextInstance’ Event Procedure, You can make any program you want, anyway this code Help you to know how to make that:
Console Application:
https://barnamenevis.org/attachment.php?attachmentid=154149&stc=1&d=1667325874
Module Module1
Dim WithEvents DestinationProcess As Process
Sub Main()
Dim Command As String = ""
Dim DestinationApp As String = String.Format("{0}{1}", My.Application.Info.DirectoryPath, _
"\DestinationApp.exe")
Dim params() As String = {""}
Dim Args As String = ""
Do Until Command.ToLower = "quit"
Console.Write("Send Info>")
Command = Console.ReadLine
Console.WriteLine()
params = Command.Split(Space(1))
Select Case params(0).ToLower
Case "set", "setinfo"
Args = ""
If params.Length > 1 Then
For i = 1 To params.Length - 1
Args += params(i) + If(i = params.Length - 1, "", Space(1))
Next
DestinationProcess = Process.Start(DestinationApp, Args)
Else
Console.WriteLine("Use Set Command with Parameters {[/n:<name>] [/f:<family>] [/b:<birthday>] [/m:<mobile>] [/ph:<phone>] [/i:<image file path>]}")
End If
End Select
Console.WriteLine()
Loop
End Sub
End Module
Use Parameters:
Set /n:{Name} /f:{Family} /b:{Birthday} /m:{mobileNumber} /ph:{PhoneNumber} /i:{Image File Path}
You can also Modify Each one of this options when you want by use ‘Set’ or ‘SetInfo’ Command.
Download Demo...
Source Application(Source Code), {Console Application}
Destination Application(Source Code), {Windows Forms Application}
If you want to use Command Prompt or Registry Command for Send Command to your own-Application:
Add this Code to 'StartupNextInstance' Event of Application Events:
Select Case e.CommandLine.Count
Case 1
Select Case e.CommandLine(0).ToLower
Case "quit"
End
End Select
End Select
Good luck.