PeerCollaboration.RegisterApplication Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers the specified PeerApplication for a collaboration session with the calling peer.
public:
static void RegisterApplication(System::Net::PeerToPeer::Collaboration::PeerApplication ^ application, System::Net::PeerToPeer::Collaboration::PeerApplicationRegistrationType type);
[System.Security.SecurityCritical]
public static void RegisterApplication (System.Net.PeerToPeer.Collaboration.PeerApplication application, System.Net.PeerToPeer.Collaboration.PeerApplicationRegistrationType type);
[<System.Security.SecurityCritical>]
static member RegisterApplication : System.Net.PeerToPeer.Collaboration.PeerApplication * System.Net.PeerToPeer.Collaboration.PeerApplicationRegistrationType -> unit
Public Shared Sub RegisterApplication (application As PeerApplication, type As PeerApplicationRegistrationType)
Parameters
- application
- PeerApplication
The PeerApplication for which to register the calling peer within the associated scope (global, local, and link-local).
The type of registration to perform. The application may be registered for just the calling peer or for all peers using the machine.
- Attributes
Exceptions
The Path property on the PeerApplication object passed to
application
isnull
.The peer application instance provided has the same globally unique Id as an application which is already registered. The existing registration must be unregistered before a new application can be registered with the provided identifier.
The application
and type
parameters cannot be null
. Both parameters must be specified.
The type parameter is not set to a known value in the PeerApplicationRegistrationType enumeration.
The RegisterApplication(PeerApplication, PeerApplicationRegistrationType) operation cannot be completed until the caller has signed-in to the infrastructure.
Examples
The following code example illustrates how to register an application with the Collaboration infrastructure:
// Registering Notepad.exe as a collab application with a fixed GUID.
// Note: If you're using the application to send invitations,
// the same application with the same GUID must be registered on the remote peer machine.
private static PeerApplication RegisterCollabApp()
{
PeerApplication application = null;
string pathToApp = "%SystemRoot%\\notepad.exe";
Guid appGuid = new Guid(0xAAAAAAAA, 0xFADE, 0xDEAF, 0xBE, 0xEF, 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAE);
application = new PeerApplication();
application.Id = appGuid;
application.Path = pathToApp;
application.Description = "Peer Collaboration Sample -- notepad.exe";
application.PeerScope = PeerScope.All;
application.CommandLineArgs = "n";
application.Data = ASCIIEncoding.ASCII.GetBytes("Test");
Console.WriteLine("Attempting to register the application \"notepad.exe\"...");
try
{
PeerApplicationCollection pac = PeerCollaboration.GetLocalRegisteredApplications(PeerApplicationRegistrationType.AllUsers);
if (pac.Contains(application))
{
Console.WriteLine("The application is already registered on the peer.");
}
else
{
PeerCollaboration.RegisterApplication(application, PeerApplicationRegistrationType.AllUsers);
Console.WriteLine("Application registration succeeded!");
}
}
catch (ArgumentException argEx)
{
Console.WriteLine("The application was previously registered with the Peer Collaboration Infrastructure: {0}.", argEx.Message);
}
catch (PeerToPeerException p2pEx)
{
Console.WriteLine("The application failed to register with the Peer Collaboration Infrastructure: {0}", p2pEx.Message);
}
catch (Exception ex)
{
Console.WriteLine("An unexpected exception occurred when trying to register the application: {0}.", ex.Message);
}
return application;
}
Remarks
The calling peer is required to sign in to the peer collaboration infrastructure with the SignIn method prior to calling this method.
Access to this method requires a PermissionState of Unrestricted. This state is created when the Peer collaboration session begins.