VB6 question-Determine Browser and open files
Ok, I need some assistance with VB6. I have two items that I can't seem to find information on. Here is what I am needing:
1. I need to be able to determine, through VB6 itself, what the users computer is using for its default web browser. I can do it through ASP but I can't seem to determine through VB.
2. I need to know how to determine if a file is already open or not. My program has 4 separate main programs to it. I need to be able to determine how to know if any of those 4 programs are open if at all possible.
Thanks.
BigJay
Re: VB6 question-Determine Browser and open files
Quote:
Originally Posted by BigJay
Ok, I need some assistance with VB6. I have two items that I can't seem to find information on. Here is what I am needing:
1. I need to be able to determine, through VB6 itself, what the users computer is using for its default web browser. I can do it through ASP but I can't seem to determine through VB.
2. I need to know how to determine if a file is already open or not. My program has 4 separate main programs to it. I need to be able to determine how to know if any of those 4 programs are open if at all possible.
Thanks.
BigJay
To get the default browser, use something like this. Start a new project, and replace all code in the form with this:
VB Code:
Option Explicit
Private Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Long) As Long
Private Function LongPath(ByVal ShortPath As String) As String
Dim lonRet As Long, strLong As String
strLong = String$(1024, " ")
lonRet = GetLongPathName(ShortPath, strLong, Len(strLong))
If lonRet > Len(strLong) Then
strLong = String$(lonRet + 1, " ")
lonRet = GetLongPathName(ShortPath, strLong, Len(strLong))
End If
If lonRet > 0 Then
LongPath = Left$(strLong, lonRet)
End If
End Function
Private Function DefaultBrowser() As String
Dim strReg As String, objReg As Object
Set objReg = CreateObject("Wscript.Shell")
strReg = objReg.regread("HKEY_CLASSES_ROOT\HTTP\shell\open\command\")
strReg = Replace$(strReg, Chr$(34), "")
strReg = Mid$(strReg, 1, InStr(1, strReg, ".exe", vbTextCompare) + 3)
DefaultBrowser = strReg
End Function
Private Sub Form_Load()
Dim strBrowser As String
strBrowser = LongPath(DefaultBrowser)
MsgBox strBrowser
End Sub
To find if one of your programs are open or not, you can use the FindWindow() API function. There is code for this in the CodeBank.
Re: VB6 question-Determine Browser and open files
Great. This helps alot.
I have a question on detecting an open program. A little more in depth is that the program(s) I need to watch for open would be running through a network and they could be running on another computer on the network, not the computer that is running the program trying to detect open programs. How can I detect a program being open on any machine on the network that may not be running on that specific machine?
Thanks.