EventSourceCreationData.MachineName Właściwość

Definicja

Pobiera lub ustawia nazwę komputera, na którym ma zostać zarejestrowane źródło zdarzeń.

public:
 property System::String ^ MachineName { System::String ^ get(); void set(System::String ^ value); };
public string MachineName { get; set; }
member this.MachineName : string with get, set
Public Property MachineName As String

Wartość właściwości

Nazwa systemu, na którym ma zostać zarejestrowane źródło zdarzeń. Wartość domyślna to komputer lokalny (".").

Wyjątki

Nazwa komputera jest nieprawidłowa.

Przykłady

Poniższy przykład kodu ustawia właściwości konfiguracji źródła zdarzeń z argumentów wiersza polecenia. Argumenty wejściowe określają nazwę źródła zdarzeń, nazwę dziennika zdarzeń, nazwę komputera i plik zasobu komunikatu o zdarzeniu. Ten przykład jest częścią większego przykładu udostępnionego EventSourceCreationData dla klasy.

EventSourceCreationData ^ mySourceData = gcnew EventSourceCreationData( "","" );
bool registerSource = true;

// Process input parameters.
if ( args->Length > 1 )
{
   
   // Require at least the source name.
   mySourceData->Source = args[ 1 ];
   if ( args->Length > 2 )
   {
      mySourceData->LogName = args[ 2 ];
   }

   if ( args->Length > 3 )
   {
      mySourceData->MachineName = args[ 3 ];
   }

   if ( (args->Length > 4) && (args[ 4 ]->Length > 0) )
   {
      mySourceData->MessageResourceFile = args[ 4 ];
   }
}
else
{
   
   // Display a syntax help message.
   Console::WriteLine( "Input:" );
   Console::WriteLine( " source [event log] [machine name] [resource file]" );
   registerSource = false;
}


// Set defaults for parameters missing input.
if ( mySourceData->MachineName->Length == 0 )
{
   
   // Default to the local computer.
   mySourceData->MachineName = ".";
}

if ( mySourceData->LogName->Length == 0 )
{
   
   // Default to the Application log.
   mySourceData->LogName = "Application";
}
EventSourceCreationData mySourceData = new EventSourceCreationData("", "");
bool registerSource = true;

// Process input parameters.
if (args.Length > 0)
{
    // Require at least the source name.

    mySourceData.Source = args[0];

    if (args.Length > 1)
    {
        mySourceData.LogName = args[1];
    }

    if (args.Length > 2)
    {
        mySourceData.MachineName = args[2];
    }
    if ((args.Length > 3) && (args[3].Length > 0))
    {
        mySourceData.MessageResourceFile = args[3];
    }
}
else
{
    // Display a syntax help message.
    Console.WriteLine("Input:");
    Console.WriteLine(" source [event log] [machine name] [resource file]");

    registerSource = false;
}

// Set defaults for parameters missing input.
if (mySourceData.MachineName.Length == 0)
{
    // Default to the local computer.
    mySourceData.MachineName = ".";
}
if (mySourceData.LogName.Length == 0)
{
    // Default to the Application log.
    mySourceData.LogName = "Application";
}
         Dim mySourceData As EventSourceCreationData = new EventSourceCreationData("", "")
         Dim registerSource As Boolean = True

         ' Process input parameters.
         If args.Length > 0
             ' Require at least the source name.

             mySourceData.Source = args(0)

             If args.Length > 1

                 mySourceData.LogName = args(1)
 
             End If
             If args.Length > 2

                 mySourceData.MachineName = args(2)
 
             End If
             If args.Length > 3 AndAlso args(3).Length > 0

                 mySourceData.MessageResourceFile = args(3)
 
             End If

         Else 
             ' Display a syntax help message.
             Console.WriteLine("Input:")
             Console.WriteLine(" source [event log] [machine name] [resource file]")

             registerSource = False
         End If

         ' Set defaults for parameters missing input.
         If mySourceData.MachineName.Length = 0
         
             ' Default to the local computer.
             mySourceData.MachineName = "."
         End If
         If mySourceData.LogName.Length = 0
             ' Default to the Application log.
             mySourceData.LogName = "Application"
         End If

Uwagi

Wartość MachineName nie może być pustym ciągiem. Jeśli nazwa maszyny nie jest jawnie ustawiona, domyślnie jest to komputer lokalny (".").

Podczas rejestrowania źródła na komputerze zdalnym należy mieć uprawnienia administracyjne na tym komputerze, aby zapisywać wartości rejestru z wystarczającymi uprawnieniami.

Dotyczy

Zobacz też