使用Java锁定屏幕 [英] Use Java to lock a screen

查看:222
本文介绍了使用Java锁定屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我只需要创建一个应用程序(具有某种用户访问权限),第一个屏幕是一个全屏窗口,无法在不输入有效用户名和密码的情况下最小化或关闭。像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!

推荐答案

有一次,我写了一些东西Java,你无法逃脱。真的不可能。它适用于Windows。你去吧:

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();
  }
}

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

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.

这篇关于使用Java锁定屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆