LockDown PC based on availability of Bluetooth Device


This article describes a method of locking the PC when the user is not around.Actually it detects the user mobile phone’s bluetooth (And yes 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 written in  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. So first we need to find out the MAC address of the phone’s bluetooth module and we can then check the presence of the same perodically and trigger PC lockdown based on its availability. It’s not like only phone can be used, basically it can be used with any Bluetooth based device.

To find the the MAC  address of the phone to be tracked, use the following code,

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) {}

Now we can use the found MAC address in the following script. The script is only to to show the logic like how it will work, but if you want to use it you need to loop it with a certain delay so that it can run to check the presence of the device periodically.


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");


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




Hope this will help you in some way !!

Related posts

Leave a Comment