private void check_event_log_thread() {
/* Examples of valid names on my machine:
Microsoft-Windows-TWinUI/Operational
Microsoft-Windows-AppxPackaging/Operational
Microsoft-Windows-AppModel-Runtime/admin
The remote machine:
- It must be discoverable
- Account you use must belong to "Event Log Readers"
- You must enable the Remote Event Log Management exception in the Windows Firewall Settings on the remote computer to which you want to connect.
- "Remote Registry" must be running on the remote computer
*/
while (!closed_) {
Thread.Sleep(250);
bool needs_check = false;
string[] event_logs = null;
string remote_machine_name = null, remote_domain_name = null, remote_user_name = null, remote_password_name = null;
this.async_call_and_wait(() => {
needs_check = typeTab.SelectedIndex == 1;
event_logs = selectedEventLogs.Text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
remote_machine_name = remoteMachineName.Text;
remote_domain_name = remoteDomain.Text;
remote_user_name = remoteUserName.Text;
remote_password_name = remotePassword.Text;
if (!eventLogs.Enabled)
// user hasn't connected to remote machine yet
needs_check = false;
});
if (!needs_check)
continue;
// check all names typed by user
List<string> dont_exist = new List<string>();
foreach ( string log in event_logs)
try {
// note: for non standard logs, such as "Microsoft-Windows-TWinUI/Operational", Exists() returns false
bool exists = remote_machine_name != "" ? false : EventLog.Exists(log);
if ( !exists)
exists = remote_event_log_exists(log, remote_machine_name, remote_domain_name, remote_user_name, remote_password_name);
if ( !exists)
dont_exist.Add(log);
} catch {
dont_exist.Add(log);
}
this.async_call_and_wait(() => {
if (dont_exist.Count < 1) {
eventLogCheckStatus.Text = "OK";
eventLogCheckStatus.ForeColor = Color.ForestGreen;
} else {
eventLogCheckStatus.Text = "Logs [" + util.concatenate(dont_exist, ", ") + "] don't exist.";
eventLogCheckStatus.ForeColor = Color.Red;
}
});
}
}