PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: paulDiagnos on June 05, 2007, 08:55:26 AM

Title: Rs232
Post by: paulDiagnos on June 05, 2007, 08:55:26 AM
Hi guys,

How can i work out what program is using what com port?
I dont mind coding it myself, but if anyone has a
program already written for this i would be grateful.

thanks Paul .
Title: Re: Rs232
Post by: paulDiagnos on June 08, 2007, 05:30:59 AM
OK found the answer ish ..
there is a program that output al ot of info about your system called handle . you can use the output to determine if programs use the com ports.

http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/Handle.mspx from sys internals.

heres an example for 98


ROUGH CODE

If Dir$(tempdir+"process.exe") = "" Then MsgBox "Sysinternals process.exe required" : Exit Function
If Dir$(tempdir+"handle.exe") = "" Then MsgBox "Sysinternals Handle.exe required" : Exit Function
If Dir$(tempdir+"pv.exe") = "" Then MsgBox "Sysinternals pv.exe required" : Exit Function
Kill tempdir+"TEMP.txt"
CmdLn = ENVIRON$("COMSPEC") + " /C " +tempdir+"handle.exe -a >"+tempdir+"TEMP.txt"
Shell (CmdLn ,1)
MsgBox CmdLn

Open tempdir+"temp.txt" For Input As filenum
FileScan #filenum, Records To count&
Dim Devices(1 To count&) As String
Line Input #filenum, devices() To updatecount&
Close #filenum

Dim D As LONG
Dim PROCESS As String
x$ = "Serial"
I=1
For D=1 To UPDATECOUNT&
If MID$(DEVICES(D),1,1) = "-" Then
Array Scan devices(I),From 8 To 7+Len(x$),Collate UCase, =x$, To B

If B <> 0 Then
'MsgBox devices(I+b-1) +STR$(I)+ str$(b)
For k& = b+i To 1 step -1
If mid$(devices(k&),1,1) = "-" Then
process= parse$(devices(k&+1), " ",1)
If MsgBox ("Busy Comms has detected that " + process _
+ " is using a serial port " +$crlf + "Are you sure you want to end this process?", %MB_YesNO Or %MB_ICONQUESTION,"Autologic Port Check") = 6 Then
CmdLn = ENVIRON$("COMSPEC") + " /C " +tempdir +"pv.exe -k -f " + process

Shell cmdln, 1
End If
Exit
End If
Next
I=i+B+1
End If

End If


Next


------