Exemplo n.º 1
0
        public MouseWatcher(IBeamgunSettings settings, WorkstationLocker locker, Action <string> report, Action <string> alarm, Func <bool> disabled)
        {
            var MouseQuery = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance isa \"Win32_PointingDevice\"");

            _watcher = new ManagementEventWatcher(MouseQuery);
            _watcher.EventArrived += (caller, args) =>
            {
                if (disabled())
                {
                    return;
                }
                var obj = (ManagementBaseObject)args.NewEvent["TargetInstance"];
                alarm($"Alerting on mouse insertion: " +
                      $"{obj["Name"]} " +
                      $"{obj["Caption"]} " +
                      $"{obj["Description"]} " +
                      $"{obj["DeviceID"]} " +
                      $"{obj["Manufacturer"]} " +
                      $"{obj["PNPDeviceID"]}.");
                if (!settings.LockOnMouse)
                {
                    return;
                }
                report(locker.Lock()
                    ? "Successfully locked the workstation."
                    : "Could not lock the workstation.");
            };
            _watcher.Start();
        }
Exemplo n.º 2
0
        public KeyboardWatcher(IBeamgunSettings settings, WorkstationLocker locker, Action <string> report, Action <string> alarm)
        {
            var keyboardQuery = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance isa \"Win32_Keyboard\"");

            _watcher = new ManagementEventWatcher(keyboardQuery);
            _watcher.EventArrived += (caller, args) =>
            {
                var obj = (ManagementBaseObject)args.NewEvent["TargetInstance"];
                alarm($"Alerting on keyboard insertion: " +
                      $"{obj["Name"]} " +
                      $"{obj["Caption"]} " +
                      $"{obj["Description"]} " +
                      $"{obj["DeviceID"]} " +
                      $"{obj["Layout"]} " +
                      $"{obj["PNPDeviceID"]}.");
                if (!settings.LockWorkstation)
                {
                    return;
                }
                report(locker.Lock()
                    ? "Successfully locked the workstation."
                    : "Could not lock the workstation.");
            };
            _watcher.Start();
        }
Exemplo n.º 3
0
        public KeyboardWatcher(IBeamgunSettings settings, WorkstationLocker locker, Action <string> report, Action <string> alarm, Func <bool> disabled)
        {
            var keyboardQuery = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance isa \"Win32_Keyboard\"");

            _watcher = new ManagementEventWatcher(keyboardQuery);
            _watcher.EventArrived += (caller, args) =>
            {
                if (disabled())
                {
                    return;
                }
                var obj = (ManagementBaseObject)args.NewEvent["TargetInstance"];
                alarm($"Alerting on keyboard insertion: " +
                      $"{obj["Name"]} " +
                      $"{obj["Caption"]} " +
                      $"{obj["Description"]} " +
                      $"{obj["DeviceID"]}" +
                      $"{obj["Layout"]} " +
                      $"{obj["PNPDeviceID"]}.");
                if (!settings.LockOnKeyboard)
                {
                    return;
                }
                if (WhiteList.WhiteListed(obj))
                {
                    report($"Device is whitelisted, remove {obj["PNPDeviceID"]} from {WhiteList.WhiteFilename} if you've changed your mind.");
                    return;
                }
                report(locker.Lock()
                    ? "Successfully locked the workstation."
                    : "Could not lock the workstation.");
            };
            _watcher.Start();
        }