zoukankan      html  css  js  c++  java
  • c#实现锁屏及禁止键盘和鼠标

    1.要实现锁定系统不让别人用,可以调用系统锁定API函数来实现

    //引入API函数
            [DllImport("user32 ")]
            public static extern bool LockWorkStation();//这个是调用windows的系统锁定

    在需要的时候直接写LockWorkStation();就可以啦!不信试试看!

    2.API函数锁定键盘及鼠标

    [DllImport("user32.dll")]
            static extern void BlockInput(bool Block);

    需要的时候就直接写:

    BlockInput(true);//锁定鼠标及键盘

    BlockInput(false);//解除键盘鼠标锁定

    但是这种方式还是不能锁定ctrl+alt+delete,也就是还可以打开任务管理器,怎么办呢?

    请看下面的方法:

    3.屏蔽ctrl+alt+delete

    FileStream fs = new FileStream(Environment.ExpandEnvironmentVariables("%windir%\\system32\\taskmgr.exe"), FileMode.Open);
                //byte[] Mybyte = new byte[(int)MyFs.Length];
                //MyFs.Write(Mybyte, 0, (int)MyFs.Length);
                //MyFs.Close(); //用文件流打开任务管理器应用程序而不关闭文件流就会阻止打开任务管理器

      System.Threading.Thread.Sleep(1000);
                BlockInput(true);
                SetCursorPos(1145, 120);
                mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
                mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
                BlockInput(false);
               
                SetCursorPos(400, 420);
  • 相关阅读:
    修复 Visual Studio Error “No exports were found that match the constraint”
    RabbitMQ Config
    Entity Framework Extended Library
    Navisworks API 简单二次开发 (自定义工具条)
    NavisWorks Api 简单使用与Gantt
    SQL SERVER 竖表变成横表
    SQL SERVER 多数据导入
    Devexpress GridControl.Export
    mongo DB for C#
    Devexress XPO xpPageSelector 使用
  • 原文地址:https://www.cnblogs.com/gwazy/p/2732479.html
Copyright © 2011-2022 走看看