I need to verify when someone logs into Windows incorrectly and perform an action

1

Hello, I am programming in C # and I have a service that starts with Windows and I need to know how to perform an action when I detect it when a user logs incorrectly when logging in. Windows

    
asked by Angel Enrique Herrera Crespo 06.10.2016 в 09:05
source

1 answer

1

You could use the events of the class

SystemEvents Class

to detect when it authenticates in windows, although I do not see that there is an incorrect login event specifically

But you could evaluate using the events of WMI by means of Win32_LogonSession and

ManagementEventWatcher Class

as it is proposed here

Get notified from logon and logoff

private readonly static WqlEventQuery query = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance ISA \"Win32_LogonSession\"");


ManagementEventWatcher watcher = new ManagementEventWatcher(query);
watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
watcher.Start();

assigning the handler that triggers when a wmi event occurs

private void HandleEvent(object sender, EventArrivedEventArgs e)
{
    ManagementBaseObject f = (ManagementBaseObject)e.NewEvent["TargetInstance"];

     //resto codigo
}
    
answered by 06.10.2016 в 18:13