Thursday, November 14, 2013

Lock PC using Mobile Bluetooth

   This article describes a method of locking the PC when the user is not around.Actually it detects the user mobile phone's bluetooth (Obviously it has to be turned on all the time.) and if the application can't find the phone it sends a command to lock down the workstation.The codes are of JAVA and it uses the Bluecove library ,which is a open source one.The app uses the bluetooth mac address instead of the name so as to provide security.Hope this will help you.

 Codes:
  • To find the Bluetooth mac address :
package com.oksbwn.bluetooth;
import java.io.IOException;
import javax.bluetooth.*;
import javax.swing.JOptionPane;
public class BluetoothSearchAddress implements DiscoveryListener {
    private LocalDevice localDevice;
    private DiscoveryAgent agent;
   public BluetoothSearchAddress () throws BluetoothStateException {
        localDevice = LocalDevice.getLocalDevice();
        agent = localDevice.getDiscoveryAgent();
    }
    
    public void inquiry() throws BluetoothStateException {
        agent.startInquiry(DiscoveryAgent.GIAC, this);
    }
    public void deviceDiscovered(RemoteDevice device, DeviceClass devClass) {
        String devicesAndAdress="<html><body>";
        try {
            devicesAndAdress=devicesAndAdress+device.getFriendlyName(false)+":"+device.getBluetoothAddress();
        } catch (IOException ex) {}      
JOptionPane.showMessageDialog(null, devicesAndAdress);
    }
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { }
    public void serviceSearchCompleted(int transID, int responseCode) { }
    public void inquiryCompleted(int discType){}
}
  • To lock PC if mobile not found.
     package com.oksbwn.System;
     import java.io.IOException;
     import javax.microedition.io.Connection;
     import javax.microedition.io.Connector;
public class Hibernate
{
// public static void main(String args[]) throws Exception
 public void doit() throws IOException{
       try {
           Connection connection = Connector.open( "btgoep://" +"THE DEVIC BT. ADDRESS" + ":9");
           connection.close();
       }
       catch (Exception e) {
     //r.exec("shutdown -h");//s for shutdown r restart
     Runtime rt = Runtime.getRuntime();
     rt.exec("C:\\Windows\\System32\\rundll32.exe user32.dll,LockWorkStation");
     }
       }
}



No comments:

Post a Comment