Пример #1
0
 private void LoadSources()
 {
     if (cboLog.SelectedIndex > -1)
     {
         try
         {
             List <ListViewItem> sources = new List <ListViewItem>();
             lvwSources.BeginUpdate();
             lvwSources.Items.Clear();
             foreach (string s in EventLogUtil.GetEventSources(txtComputer.Text, cboLog.SelectedItem.ToString()))
             {
                 ListViewItem lvi = new ListViewItem(s);
                 if (SelectedEventLogEntry.Sources.Contains(s))
                 {
                     lvi.Checked = true;
                 }
                 sources.Add(lvi);
             }
             lvwSources.Items.AddRange(sources.ToArray());
         }
         catch (System.Security.SecurityException)
         {
             MessageBox.Show("This editor window requires that the application runs in Administrative mode to access all functionality!\r\nPlease restart the application in 'Administrative' mode if you need to access all functionality.", "Admin Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             lvwSources.EndUpdate();
         }
     }
 }
Пример #2
0
        private void LoadComputerEventsLogs()
        {
            try
            {
                cboLog.Items.Clear();
                if (txtComputer.Text.Trim().Length == 0)
                {
                    return;
                }
                if (System.Net.Dns.GetHostAddresses(txtComputer.Text).Length == 0)
                {
                    return;
                }

                foreach (string eventLogName in EventLogUtil.GetEventLogNames(txtComputer.Text))
                {
                    cboLog.Items.Add(eventLogName);
                }
                if (SelectedEventLogEntry.EventLog != null)
                {
                    cboLog.SelectedItem = SelectedEventLogEntry.EventLog;
                }
                else
                {
                    cboLog.SelectedItem = "Application";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Load Event logs", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            CheckOkEnabled();
        }