lock window using java code

import java.util.Scanner;

public class LockExample {

public static void main(String[] args) {

try{

Scanner s=new Scanner(System.in);

System.out.println("Enter lock to Lock window.");

    String cmd=s.next();

if(cmd.equals("lock")){

Runtime rt = Runtime.getRuntime();

  Process pr = rt.exec("C:\\Windows\\System32\\rundll32.exe user32.dll,LockWorkStation");

System.out.println("success fully lock");

}else{

System.out.println("lock failed");

}

}catch (Exception e) {

System.out.println(e);

}

}

}

No comments: