使用Java锁定屏幕

发布于 2024-11-25 09:26:08 字数 145 浏览 2 评论 0原文

基本上我只需要创建一个应用程序(具有某种用户访问权限),其第一个屏幕是一个全屏窗口,如果不输入有效的用户名和密码,则无法最小化或关闭该窗口。类似 Windows 屏幕保护程序之类的东西。能做到吗?我应该查看哪些图书馆?这就是我所需要的,如果我的问题不完整或不清楚,请随时提问!

Basically i just need to create an application (with sort of user access) which first screen is a fullscreen window that cannot be minimized or closed without entering valid username and password. Something like windows screensaver. Can it be done? What libraries should i look into? This is all i need, if my question is incomplete or unclear, feel free to ask!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹤仙姿 2024-12-02 09:26:08

有一次,我用 Java 写了一些东西,你无法逃脱它。实在是不可能。它适用于 Windows。给你:

import java.awt.Robot;
import javax.swing.JFrame;


public class WindowsSecurity implements Runnable 
{
  private JFrame frame;
  private boolean running;

  public WindowsSecurity(JFrame yourFrame)
  {
    this.frame = yourFrame;
    new Thread(this).start();
  }

  public void stop()
  {
     this.running = false;
  }

  public void run() {
    try {
      this.terminal.getParentFrame().setAlwaysOnTop(true);
      this.terminal.getParentFrame().setDefaultCloseOperation(0);
      kill("explorer.exe"); // Kill explorer
      Robot robot = new Robot();
      int i = 0;
      while (running) {
         sleep(30L);
         focus();
         releaseKeys(robot);
         sleep(15L);
         focus();
         if (i++ % 10 == 0) {
             kill("taskmgr.exe");
         }
         focus();
         releaseKeys(robot);
      }
      Runtime.getRuntime().exec("explorer.exe"); // Restart explorer
    } catch (Exception e) {

    }
  }

  private void releaseKeys(Robot robot) {
    robot.keyRelease(17);
    robot.keyRelease(18);
    robot.keyRelease(127);
    robot.keyRelease(524);
    robot.keyRelease(9);
  }

  private void sleep(long millis) {
    try {
      Thread.sleep(millis);
    } catch (Exception e) {

    }
  }

  private void kill(String string) {
    try {
      Runtime.getRuntime().exec("taskkill /F /IM " + string).waitFor();
    } catch (Exception e) {
    }
  }

  private void focus() {
    this.frame.grabFocus();
    this.frame.requestFocus();
  }
}

这段代码的背景:我写了某种假终端,我可以在其中显示我想要的一切。例如,愚蠢的 Windows 消息如:“未找到键盘,请按任意键继续”。我用它作为学校的笑话。启动这个应用程序并离开房间,一分钟后它会自动注销Windows帐户。但我没想到会有老师用Ctrl-Alt-Del杀死我的应用程序。他在我的个人文件中留下了一条信息,其中写下了他所做的事情,并以“我打败了你,哈哈,我是邪恶的”结束了他的信息。所以,我想和他一起竞争。然后写了这段代码。他在学校里尝试了五次以上逃离该应用程序,但他做不到(我也做不到:D)。当然,他可以关闭机器或注销。但目标是访问我的个人文件。

Once, I wrote something in Java, out of which you can't escape. Really impossible. It is for Windows. Here you go:

import java.awt.Robot;
import javax.swing.JFrame;


public class WindowsSecurity implements Runnable 
{
  private JFrame frame;
  private boolean running;

  public WindowsSecurity(JFrame yourFrame)
  {
    this.frame = yourFrame;
    new Thread(this).start();
  }

  public void stop()
  {
     this.running = false;
  }

  public void run() {
    try {
      this.terminal.getParentFrame().setAlwaysOnTop(true);
      this.terminal.getParentFrame().setDefaultCloseOperation(0);
      kill("explorer.exe"); // Kill explorer
      Robot robot = new Robot();
      int i = 0;
      while (running) {
         sleep(30L);
         focus();
         releaseKeys(robot);
         sleep(15L);
         focus();
         if (i++ % 10 == 0) {
             kill("taskmgr.exe");
         }
         focus();
         releaseKeys(robot);
      }
      Runtime.getRuntime().exec("explorer.exe"); // Restart explorer
    } catch (Exception e) {

    }
  }

  private void releaseKeys(Robot robot) {
    robot.keyRelease(17);
    robot.keyRelease(18);
    robot.keyRelease(127);
    robot.keyRelease(524);
    robot.keyRelease(9);
  }

  private void sleep(long millis) {
    try {
      Thread.sleep(millis);
    } catch (Exception e) {

    }
  }

  private void kill(String string) {
    try {
      Runtime.getRuntime().exec("taskkill /F /IM " + string).waitFor();
    } catch (Exception e) {
    }
  }

  private void focus() {
    this.frame.grabFocus();
    this.frame.requestFocus();
  }
}

Background of this code: I wrote some kind of fake terminal in which I could let appear everything what I wanted. Eg, the stupid Windows messages like: "Keyboard not found, press any key to continue". I used it as a joke on school. Fire up this app and leave the room, it would log out the Windows account automatically after one minute. But I hadn't thought that there would be a teacher that used Ctrl-Alt-Del to kill my application. He left a message in my personal documents in which he wrote what he did and ended his message with "I've beaten you, haha I'm evil". So, I wanted to go in competition with him. And then wrote this code. He tried more than five times in school to escape from the app, but he couldn't (I can't as well :D). Of course he could turn off the machine or log out. But the target was to access my personal documents.

各自安好 2024-12-02 09:26:08

在任何一个半像样的操作系统中,操作系统将负责为每个进程分配一个区域或窗口。

您将需要检查执行此操作的每个操作系统方法,并使用 JNI 以本机代码(可能是 C 或 C++)实现它。

In any half-decent OS, the OS will be the one in charge of assigning an area or window to each process.

You will need to check each OS method of doing that, and implement it in native code (probably C or C++) using JNI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文