Sign in to follow this  
Followers 0
anixon

Computer Lock (Bluetooth)

15 posts in this topic

#1 ·  Posted (edited)

This script can trigger the lock down of a computer when it looses connectivity with a paired mobile phone

Would have preferred not to have used hypertrm as the means by which the mobile phone modem can be tested for connectivity - not sure how to do that;

If hypertrm is the best option I would like it to start it minimised or hide the windows. @SW_Hide works after the screen is displayed - not sure how to make it totally stealthy;

Would have preferred to start hypertrm without the connection screen being opened - don't know how to do that it would however eliminate some of the 'Send' code.

Would like to replace the sleep(5000) statement with a routine based on the script getting the

OK response from the modem but not sure how to do that.

Hypertrm is opened and closed to force connectivity to be performed so that the connectivity status assigned to $text is read.

Whilst the code might not be elegant it actually works (less than 3 weeks scripting experience).

; Monitor a Bluetooth Mobile Phone
;  
; When the phone is out of range resulting in no connectivity
; the lock the computer routine is called
;
; When the phone is in range result in connectivity
; the unlock the computer routine is called
;
; Exit this routine has not yet been written so for the moment
; it just loops so you will need to close it using CTRL-ALT-DEL
;
$Flag1 = 0
$Flag2 = 0
while 1
Run('c:\program files\windows nt\hypertrm.exe')
WinWaitActive("Connection Description")
ControlClick("Connection Description", "", "Button2")
Send("{Space}{Enter}")
Sleep(5000)
$text = StringLeft(WinGetText("New Connection -", ""), 9)    
if ($text = "Connected") AND $Flag1 = 0 then
     $file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)
     FileWriteLine($file, "")
     FileWriteLine($file, "-------------------------------------------------")
     FileWriteLine($file, "Mobile connected      " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))
     FileClose($file) 
;Run routine to unlock the computer
     $Flag1 = 1
     $Flag2 = 0
elseIf ($text <> "Connected") AND $Flag2 = 0 then
     $file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)
     FileWriteLine($file, "Mobile not connected   " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))
     FileWriteLine($file, "-------------------------------------------------")
     FileClose($file)
;Run routine to lock the computer
     $Flag1 = 0
     $Flag2 = 1
EndIf
  $i = 0
  Do
    sleep(1000)
    $i = $i + 1
Until $i = 60
ProcessClose("hypertrm.exe")
$PID = ProcessExists("hypertrm.exe")
If $PID Then ProcessClose($PID)
Wend
;
;End of script

Look forward to comments and recommendations

;) Ant

Edited by anixon

Share this post


Link to post
Share on other sites



ok I have the sode and it runs on the syetem but it wont connect although my phone is connected to the pc and paired.. are you using any settings that are needed to be entered manually.

if I can get it working then I can comment on it.

br


You only need two tools in life: WD40 and Duct Tape.If it moves and it shouldn't, use Duct Tape.If it should move but doesnt, use WD40.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ok I have the sode and it runs on the syetem but it wont connect although my phone is connected to the pc and paired.. are you using any settings that are needed to be entered manually.

if I can get it working then I can comment on it.

br

This only works if your mobile phone has an inbuilt modem.

To test go to the Control Panel, Phones and Modems and check that you have a Bluetooth modem assigned to a COM port. Make sure your phone is on and Bluetooth is on and your PC has discovered the device. Select Properties and then go to Diagnostics and query the modem to make sure that you have connectivity. You may also need to check your Bluetooth configuration settings to make sure that the Bluetooth local service for the modem is set to auto and required. In addition go to Regedit HKEY_LOCAL_MACHINE/HARDWARE/DEVICEMAP/SERIALCOMM and check that you have a \DEVICE\BTMODEMn and DEVICE\BTPORTn installed. You could also transfer a file between your phone and PC to make sure that the Bluetooth connection is working properly.

Also open Hyperterminal and type in ATZ <Enter> and you should get an "OK" response if the modem is connected correctly

I have also found a problem with the code so please delete or remark out the following two lines

WinSetState("Connection Description", "", @SW_HIDE)

WinSetState("New Connection -", "", @SW_HIDE)

for some reason @SW_HIDE stops this code from working

$text = StringLeft(WinGetText("New Connection -", ""), 9)

if ($text = "Connected") AND $Flag1 = 0 then etc

Hope you can get it working as I would like your feed back

Cheers ;) Ant

Edited by anixon

Share this post


Link to post
Share on other sites

I have managed to get the code to work and it communicates perfectly.. but my system did not lock.. nothing happened when I went out of range of my laptop.. or my computer or my server.. nothing at all..

I will get more info for you so you can have a look at it, I am at work so I cant do much here .. whn I get home i will try on my machine.

br

Acideax


You only need two tools in life: WD40 and Duct Tape.If it moves and it shouldn't, use Duct Tape.If it should move but doesnt, use WD40.

Share this post


Link to post
Share on other sites

I have managed to get the code to work and it communicates perfectly.. but my system did not lock.. nothing happened when I went out of range of my laptop.. or my computer or my server.. nothing at all..

I will get more info for you so you can have a look at it, I am at work so I cant do much here .. whn I get home i will try on my machine.

br

Acideax

Hi. I havn't written the lock because many other subscribers appear to have already written those types of scripts so you can download their offering and incorporate it into the bluetooth monitor script.

What I published was simply a method for communicating with a mobile phone ( not the most elegant ) which can be developed for launching and closing other programs or performing user nominated processes and tasks. There needs to be another small utility for launching and closing the Mobilephone/Bluetooth monitor. I will post this script in a week or so after I have finished my current project which is a home security system.

My wife is a Teacher and she has a notebook which is used for school work so my interest is to lock it down so that you know who cannot do anything which has not been approved. Another feature would be to build in some tracking based on GPS and IP information delivered by eMail and/or SMS.

Thanks for the interest and I am please that it actually runs on a PC other than mine

Cheers ;) Ant

Share this post


Link to post
Share on other sites

I wrote a proximity lock application like this some time ago, but not with HyperTerminal. I've cleaned it up a bit since then. Here you go:

;_IEErrorHandlerRegister("ComErrFunc")
$oIEErrorHandler = ObjEvent("AutoIt.Error","ComErrFunc")
global $COMerrnotify = true
Func ComErrFunc()
    If IsObj($oIEErrorHandler) Then
        if $COMerrnotify then
            ConsoleWrite("--> ComErrFunc: COM Error Encountered in " & @ScriptName & @CR)
            ConsoleWrite("----> Scriptline = " & $oIEErrorHandler.scriptline & @CR)
            ConsoleWrite("----> Number Hex = " & Hex($oIEErrorHandler.number, 8) & @CR)
            ConsoleWrite("----> Number = " & $oIEErrorHandler.number & @CR)
            ConsoleWrite("----> Win Description = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CR)
            ConsoleWrite("----> Description = " & StringStripWS($oIEErrorHandler.description, 2) & @CR)
            ConsoleWrite("----> Source = " & $oIEErrorHandler.Source & @CR)
            ConsoleWrite("----> Help File = " & $oIEErrorHandler.HelpFile & @CR)
            ConsoleWrite("----> Help Context = " & $oIEErrorHandler.HelpContext & @CR)
            ConsoleWrite("----> Last Dll Error = " & $oIEErrorHandler.LastDllError & @crlf)
        EndIf
        $HexNumber = Hex($oIEErrorHandler.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc

; you must have NETCommOCX installed before this will work
; http://home.comcast.net/~hardandsoftware/NETCommOCX.htm
$NetComm = ObjCreate("NETCommOCX.NETComm") ;Create NETComm.ocx object
if not isobj($NetComm) then
    Msgbox(16,0,"! NETCommOCX object not instantiated!")
    Exit
EndIf

while 1
    if not DeviceInRange(7) Then ; COM7 is my bluetooth device's com port on my PC
        send("#l") ; lock the workstation
    EndIf
    sleep(60*1000) ; wait 60 seconds - adjust as per desired battery life  :)
WEnd

$NetComm = 0

Func DeviceInRange($port)

    $NetComm.CommPort = $port
    
    $COMerrnotify = false
        $NetComm.PortOpen = True
        $status = $NetComm.PortOpen
        $NetComm.PortOpen = False
    $COMerrnotify = true
    
    ConsoleWrite("Status: " & $status & @crlf)
    ; in my testing, .PortOpen = 0 means it couldn't open the port, -1 means it could
    Select
        Case $status = 0
            Return False
        Case $status = -1
            Return True
    EndSelect

EndFunc


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

I wrote a proximity lock application like this some time ago, but not with HyperTerminal. I've cleaned it up a bit since then. Here you go:

;_IEErrorHandlerRegister("ComErrFunc")
$oIEErrorHandler = ObjEvent("AutoIt.Error","ComErrFunc")
global $COMerrnotify = true
Func ComErrFunc()
    If IsObj($oIEErrorHandler) Then
        if $COMerrnotify then
            ConsoleWrite("--> ComErrFunc: COM Error Encountered in " & @ScriptName & @CR)
            ConsoleWrite("----> Scriptline = " & $oIEErrorHandler.scriptline & @CR)
            ConsoleWrite("----> Number Hex = " & Hex($oIEErrorHandler.number, 8) & @CR)
            ConsoleWrite("----> Number = " & $oIEErrorHandler.number & @CR)
            ConsoleWrite("----> Win Description = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CR)
            ConsoleWrite("----> Description = " & StringStripWS($oIEErrorHandler.description, 2) & @CR)
            ConsoleWrite("----> Source = " & $oIEErrorHandler.Source & @CR)
            ConsoleWrite("----> Help File = " & $oIEErrorHandler.HelpFile & @CR)
            ConsoleWrite("----> Help Context = " & $oIEErrorHandler.HelpContext & @CR)
            ConsoleWrite("----> Last Dll Error = " & $oIEErrorHandler.LastDllError & @crlf)
        EndIf
        $HexNumber = Hex($oIEErrorHandler.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc

; you must have NETCommOCX installed before this will work
; http://home.comcast.net/~hardandsoftware/NETCommOCX.htm
$NetComm = ObjCreate("NETCommOCX.NETComm") ;Create NETComm.ocx object
if not isobj($NetComm) then
    Msgbox(16,0,"! NETCommOCX object not instantiated!")
    Exit
EndIf

while 1
    if not DeviceInRange(7) Then ; COM7 is my bluetooth device's com port on my PC
        send("#l") ; lock the workstation
    EndIf
    sleep(60*1000) ; wait 60 seconds - adjust as per desired battery life  :)
WEnd

$NetComm = 0

Func DeviceInRange($port)

    $NetComm.CommPort = $port
    
    $COMerrnotify = false
        $NetComm.PortOpen = True
        $status = $NetComm.PortOpen
        $NetComm.PortOpen = False
    $COMerrnotify = true
    
    ConsoleWrite("Status: " & $status & @crlf)
    ; in my testing, .PortOpen = 0 means it couldn't open the port, -1 means it could
    Select
        Case $status = 0
            Return False
        Case $status = -1
            Return True
    EndSelect

EndFunc
very nice code.. but the one problem I have is that the program asks for user input on the connected phone every minuite.. I know this var can be changed but is there no way to not get the users input.. just allow the bluetooth to accept that its connected and then to just check... with no interaction from the user.

at the moment if the user does not interact the system logs me out.. this is ok as a test script but does anyone have any better ideas to make it work.

br


You only need two tools in life: WD40 and Duct Tape.If it moves and it shouldn't, use Duct Tape.If it should move but doesnt, use WD40.

Share this post


Link to post
Share on other sites

very nice code.. but the one problem I have is that the program asks for user input on the connected phone every minuite.. I know this var can be changed but is there no way to not get the users input.. just allow the bluetooth to accept that its connected and then to just check... with no interaction from the user.

at the moment if the user does not interact the system logs me out.. this is ok as a test script but does anyone have any better ideas to make it work.

br

I have brought together into one script some code, parts of have been published seperately in this forum. This scripts function is to continuously

monitor a mobile phone (switch surveillance on and off), as well as network connectivity and surveillance processing (seperate application).

The code brings together the following functionality:

1 That bluetooth and paired mobile phone connectivity is present and/or available (using Hyperterminal);

2 The stand a lone surveillance program is re-started in cirumstances where an unauthorised shutdown occurs;

3 Email/SMS Alerts processing (seperate AutoIT Script published elsewhere in this forum) for specific events;

4 Network connectivity is monitored; and

5 A visual display SplashTextOn and Date/Time stamped Log recording processing events.

Currently under construction is an interactive script which will allow a user to manually start and stop the monitor, change passwords and processing

parameters (text.ini) get SplashTextOn visual reports of system status, open log files as well closing down the surveillance process.

All of the software resides on a secured stand-a-lone box (no monitor keyboard or mouse) running Windows XP SP2 and is managed by another networked PC where Remote Desktop has been deployed. When the system is not required for surveillance the user can close it down by activating that part of the script which performs a Shutdown(13) (forced logoff power off) The system is cold booted using a wireless remote momentary switch which has been installed internally between the external power switch and the mother board.

Cheers :P Ant

CODE
;Date Time Processing

;

#include <Date.au3>

;Set stealth mode

;

$var5 = iniread(@scriptdir&"\kims.ini", "stealth", "mode", "0")

if $var5() = 1 then

opt("TrayIconHide", 1)

EndIf

; Monitor Mobile Phone, Network and Surveillance Processing

;

$Flag1 = 0

$Flag2 = 0

$Flag3 = 0

$i = 0

while 1

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

If $var24 = 0 then ;Check if Bluetooth is active

Run('c:\program files\windows nt\hypertrm.exe')

WinWaitActive("Connection Description")

ControlClick("Connection Description", "", "Button2")

WinWaitActive("New Connection - ")

Send("{Space}{Enter}")

IniWrite(@scriptdir & "\kims.ini", "bluetooth", "btsystem", "1")

If WinGetTitle("HyperTerminal", "") Then ;Error Trap no Bluetooth Modem Connectivity

ControlClick("HyperTerminal", "", "Button1")

ProcessClose("hypertrm.exe")

$PID = ProcessExists("hypertrm.exe")

If $PID Then ProcessClose($PID)

IniWrite(@scriptdir & "\kims.ini", "bluetooth", "btsystem", "0")

EndIf

Do ;Wait for Mobile connectivity test to start

$text = StringLeft(WinGetText("New Connection -", ""), 9)

until $text <> "Disconnec" or $text = 0

Do ;Wait for response to Mobile connectivity test

$text = StringLeft(WinGetText("New Connection -", ""), 9)

Until $text = "Connected" or $Text = "Disconnec" or $text = 0

If ($text = "Connected") Then

IniWrite(@scriptdir & "\kims.ini", "bluetooth", "phstatus", "1")

Else

IniWrite(@scriptdir & "\kims.ini", "bluetooth", "phstatus", "0")

EndIf

ProcessClose("hypertrm.exe")

$PID = ProcessExists("hypertrm.exe")

If $PID Then ProcessClose($PID)

EndIf

$var19 = iniread(@scriptdir&"\kims.ini", "bluetooth", "btstatus", "0")

$var23 = iniread(@scriptdir&"\kims.ini", "bluetooth", "phstatus", "0")

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

If $var23 = 1 and $var19 = 1 and $Flag2 = 0 and $var24 = 0 then ;Phone ON Processing

IniWrite(@scriptdir & "\kims.ini", "vmonitor", "vmstatus", "0")

$PID = ProcessExists("Surveillance.exe")

If $PID Then

$file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)

FileWriteLine($file, "")

FileWriteLine($file, "-------------------------------------------------")

FileWriteLine($file, "Surveillance Stopped [MA] " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileWriteLine($file, "-------------------------------------------------")

FileClose($file)

$var2 = iniread(@scriptdir&"\kims.ini", "password", "logoff", "0")

$array = StringSplit($var2, '')

For $i = 1 To UBound($array) - 1

Send('{numpad' & $array[$i] & '}') ;Stop Surveillance

sleep(100)

Next

$Flag2 = 1

$Flag3 = 0

EndIf

EndIf

$var19 = iniread(@scriptdir&"\kims.ini", "bluetooth", "btstatus", "0")

$var23 = iniread(@scriptdir&"\kims.ini", "bluetooth", "phstatus", "0")

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

if $var23 = 0 And $var19 = 1 And $var24 = 0 and $Flag3 = 0 Then ;Phone OFF Processing

$PID = ProcessExists("Surveillance.exe")

If $PID = 0 Then

$file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)

FileWriteLine($file, "")

FileWriteLine($file, "-------------------------------------------------")

FileWriteLine($file, "Surveillance Started [MA] " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileWriteLine($file, "-------------------------------------------------")

FileClose($file)

$var1 = iniread(@scriptdir&"\kims.ini", "password", "logon", "0")

$array = StringSplit($var1, '')

For $i = 1 To UBound($array) - 1 ;Start Surveillance

Send('{numpad' & $array[$i] & '}')

sleep(100)

Next

$Flag2 = 0

$Flag3 = 1

EndIf

EndIf

$var21 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmstatus", "0")

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

$PID = ProcessExists("Surveillance.exe")

If $PID = 0 And $var21 = 1 and $var24 = 0 Then ;Monitor for un-authorised shutdown of Surveillance

$file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)

FileWriteLine($file, "")

FileWriteLine($file, "Surveillance re-started " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileClose($file)

Run ("c:\program files\Surveillance\Surveillance.exe /auto") ;Surveillance re-started

$pid1 = processExists("vmonitorsmtp.exe")

If $pid1 = 0 then ;Process Email/SMS Alerts

FileWriteLine($file, "")

FileWriteLine($file, "Process email alert/s " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileClose($file)

Run(@ScriptDir & "\VMonitorSMTP.exe")

else

$file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)

FileWriteLine($file, "")

FileWriteLine($file, "O/S Alert waiting for Network " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileClose($file)

Endif

Endif

$IsCon=DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

If $iscon[0] = 0 and $var24 = 0 and $Flag1 = 0 then ;Monitor Network Connectivity

$file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)

FileWriteLine($file, "")

FileWriteLine($file, "-------------------------------------------------")

FileWriteLine($file, "No network connection " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileClose($file)

$Flag1 = 1

IniWrite(@scriptdir & "\kims.ini", "vmonitor", "network", "0")

EndIf

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

If $iscon[0] = 0 and $var24 = 0 and $Flag1 = 1 then

SplashTextOn("VMONITOR", " No network connection", 250, 50, -1, -1, 36, "times new roman", 12)

Sleep(10000)

SplashOff()

EndIf

$var24 = iniread(@scriptdir&"\kims.ini", "vmonitor", "vmskip", "0")

If $iscon[0] = 1 and $var24 = 0 and $Flag1 = 1 then

IniWrite(@scriptdir & "\kims.ini", "vmonitor", "network", "1")

$file = FileOpen(@scriptdir & "\VMonitorLog.txt", 9)

FileWriteLine($file, "Network connection restored " & (@MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC))

FileWriteLine($file, "-------------------------------------------------")

FileClose($file)

SplashTextOn("VMONITOR", " Network connection restored", 250, 50, -1, -1, 36, "times new roman", 12)

Sleep(10000)

SplashOff()

$Flag1 = 0

EndIf

$var8 = iniread(@scriptdir&"\kims.ini", "vmonitor", "countm", "60")

For $i = $var8 to 1 Step -1

Sleep(1000)

Next

Wend ;Recycle processing

;

;End of script

Share this post


Link to post
Share on other sites

I wrote a proximity lock application like this some time ago, but not with HyperTerminal. I've cleaned it up a bit since then. Here you go:

;_IEErrorHandlerRegister("ComErrFunc")
$oIEErrorHandler = ObjEvent("AutoIt.Error","ComErrFunc")
global $COMerrnotify = true
Func ComErrFunc()
    If IsObj($oIEErrorHandler) Then
        if $COMerrnotify then
            ConsoleWrite("--> ComErrFunc: COM Error Encountered in " & @ScriptName & @CR)
            ConsoleWrite("----> Scriptline = " & $oIEErrorHandler.scriptline & @CR)
            ConsoleWrite("----> Number Hex = " & Hex($oIEErrorHandler.number, 8) & @CR)
            ConsoleWrite("----> Number = " & $oIEErrorHandler.number & @CR)
            ConsoleWrite("----> Win Description = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CR)
            ConsoleWrite("----> Description = " & StringStripWS($oIEErrorHandler.description, 2) & @CR)
            ConsoleWrite("----> Source = " & $oIEErrorHandler.Source & @CR)
            ConsoleWrite("----> Help File = " & $oIEErrorHandler.HelpFile & @CR)
            ConsoleWrite("----> Help Context = " & $oIEErrorHandler.HelpContext & @CR)
            ConsoleWrite("----> Last Dll Error = " & $oIEErrorHandler.LastDllError & @crlf)
        EndIf
        $HexNumber = Hex($oIEErrorHandler.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc

; you must have NETCommOCX installed before this will work
; http://home.comcast.net/~hardandsoftware/NETCommOCX.htm
$NetComm = ObjCreate("NETCommOCX.NETComm") ;Create NETComm.ocx object
if not isobj($NetComm) then
    Msgbox(16,0,"! NETCommOCX object not instantiated!")
    Exit
EndIf

while 1
    if not DeviceInRange(7) Then ; COM7 is my bluetooth device's com port on my PC
        send("#l") ; lock the workstation
    EndIf
    sleep(60*1000) ; wait 60 seconds - adjust as per desired battery life  :)
WEnd

$NetComm = 0

Func DeviceInRange($port)

    $NetComm.CommPort = $port
    
    $COMerrnotify = false
        $NetComm.PortOpen = True
        $status = $NetComm.PortOpen
        $NetComm.PortOpen = False
    $COMerrnotify = true
    
    ConsoleWrite("Status: " & $status & @crlf)
    ; in my testing, .PortOpen = 0 means it couldn't open the port, -1 means it could
    Select
        Case $status = 0
            Return False
        Case $status = -1
            Return True
    EndSelect

EndFunc
Good code always looks great and I will try it in the next days. I guess that it is much better to test connectivity at system level rather than call and rely on the functionality of another program. I only used Hyperterminal because at the time I could not get to it any other way. However it works in testing but that is not to say that it would work in production which is what I will be doing next.

Cheers :D Ant

Cheers :P Ant

Share this post


Link to post
Share on other sites

I wrote a proximity lock application like this some time ago, but not with HyperTerminal. I've cleaned it up a bit since then.

lod3n,

great code, works perfectly for me. I have used it for a bit of home automation, and expect to expand it further in the future.

One question though...is there a way to connect to a specific bluetooth device? Or return which devices are available?

I ask because i would like the script to do one thing when my phone is available, and another when my wife's phone is available. Is this possible? ( i dont really know much about NETCommOCX or how to use it )

Thanks

Share this post


Link to post
Share on other sites

You could set up two COM ports, one for each device.

Though, I'm not sure how this applies to the script, which is aimed at locking your workstation when you leave. If you had two devices you were checking, if both were not in range, the script would lock, and I can't imagine that that's what you'd want.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Surprised theres bene no more interest after 12 months!

Very nice script, thanks for posting it.

Works very well using hyper terminal, did you ever find a way to make it run hidden so it doesnt popup every time it searches for the phone?

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I saw this post and thought it was a very cool idea. I wrote my own script based on this idea.

To use this script you must first create and save a HyperTerminal connection. Name it Bluetooth. If you need a hand connecting you phone to your pc and establishing a COM port, PM me.

TraySetIcon("c:\Program Files\Windows NT\dialer.exe",-1)
$msg = "Bluetooth Locker" & @CRLF
$lost = 0
$varsleep = 30
$pid = 0

Do
    TraySetToolTip($msg & "Searching for phone.")
    $pid = Run("C:\Program Files\Windows NT\hypertrm.exe /d bluetooth",@UserProfileDir & "\Start Menu\Programs\Accessories\Communications\HyperTerminal",@SW_HIDE)
    Sleep(7000)
    If WinExists("HyperTerminal","Unable to") Then $lost = 1
    ProcessClose($pid)
    If $lost = 0 Then 
        Wait($varsleep)
    EndIf
Until $lost <> 0

Run(@WindowsDir & "\system32\rundll32.exe user32.dll,LockWorkStation","",@SW_HIDE)

Func Wait($var)
    Do 
        TraySetToolTip($msg & "Found phone. Sleeping for " & $var & " seconds.")
        If $var - 5 >= 0 Then
            Sleep(5000)
            $var -= 5
        Else
            Sleep($var * 1000)
            $var -= $var
        EndIf
    Until $var = 0
EndFunc

Func OnAutoItExit()
    If ProcessExists($pid) Then ProcessClose($pid)
EndFunc

Edit: Fixed bug in code. Corrected UserProfile Path and specified PID fo hypertrm instead of process name incase someone is running multiple hypertrm. Doubtful, but who knows; better safe than sorry.

Edited by spudw2k

Share this post


Link to post
Share on other sites

The script is working fine but i ran into a problem, my PC would'nt lock ... after some search i found the culprit:

DisableLockWorkstation

You can enable/disable the workstation lock via a registry key so here it is

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0