Beispiel #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();
         }
     }
 }
Beispiel #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;
                }

                //EventLog[] logs = EventLog.GetEventLogs(txtComputer.Text);
                //List<EventLog> sortedLogs = new List<EventLog>();
                //for (int i = 0; i < logs.Length; i++)
                //{
                //    try
                //    {
                //        EventLog log = logs[i];
                //        string s = log.LogDisplayName; //simply try to access the property will trigger the exception if not in Admin mode
                //        sortedLogs.Add(log);
                //    }
                //    catch(System.Security.SecurityException)
                //    {
                //        //MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                //    }
                //}
                //sortedLogs.Sort((l, l2) => l.LogDisplayName.CompareTo(l2.LogDisplayName));
                //foreach (EventLog log in sortedLogs)
                //                            //(from l in logs
                //                            //  orderby l.LogDisplayName
                //                            //  select l))
                //    {
                //        cboLog.Items.Add(log.LogDisplayName);
                //    }

                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();
        }