Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect presence of program on PC 5

Status
Not open for further replies.

Gaff

Programmer
Dec 13, 2001
30
0
0
IE
Is there any way to detect the presence of Microsoft outlook on a computer. I have a vb program with an email capability and it is over a network and the computer may not have Outlook but if they try and send an email then it hangs the system. I want to be able to check for outlook on the computer and alert them if it is not on the computer.
Thanks.
 
I made this suggestion on another post, but you can use CDO to send the email. Thsi will allow you to place Multiple checks in the code.

Here is a small example of CDO
[tt]
Public Function IsUserOnline(ByRef LoginName As string, RyRef EmailSubject as String, RyRef EmailText as String) As Boolean
On Error GoTo ErrorHandler
Dim objSession As MAPI.Session
Dim objInfoStore
Dim objOutbox As Folder
Dim objNewMessage As Message
Dim objRecipients As Recipients
Dim objOneRecip As Recipient

If Not IsNull(objSession) Then

'This Line will see if the mail session is already
'open, if not it will open it. There is no use in
're-opening the mail program many times.

Set objSession = CreateObject("mapi.session")
objSession.Logon LoginName, "", False, False, 0
End If


'If the login failed then the Current User will not
'be the same as the user you tried to login with

If objSession.CurrentUser <> LoginName Then
isuseronlne = True
Exit Function
End If


'By looking for the Public Folder we can ensure that we
'have actually connected to Outlook

Set objInfoStore = objSession.InfoStores(&quot;Public Folders&quot;)
On Error Resume Next
IsUserOnline = objInfoStore.Fields(PR_STORE_OFFLINE).Value
If Err.Number <> 0 Or IsUserOnline <> 0 Then

'The PR_STORE_OFFLINE field may not exist,
'which indicates that the store is online.

IsUserOnline = False
End If


'Finally we can send our email

Set objOutbox = objSession.Outbox
Set objNewMessage = objOutbox.Messages.Add
Set objRecipients = objNewMessage.Recipients
Set objOneRecip = objRecipients.Add
With objOneRecip
.Name = LoginName
.Type = ActMsgTo
.Resolve showdialog = False
End With

With objNewMessage
.Subject = EmailSubject
.Text = EmailText
.Send
End With

Set objInfoStore = Nothing
Set objOutbox = Nothing
Set objNewMessage = Nothing
Set objRecipients = Nothing
Set objOneRecip = Nothing

Exit Function
ErrorHandler:
MsgBox &quot;EMAIL ERROR &quot; & err.Number & err.Description
End Function
[/tt]
Craig, mailto:sander@cogeco.ca
&quot;Procrastination is the art of keeping up with yesterday.&quot;
I hope my post was helpful!!!
 
I may be mis-understanding what you are after Gaff but it seems like you just want to know if a program exists, the best way I know is to determine what file runs the program, then simply see if it exists, I use the sub form load event of the program that requires it.

This example looks for Media Player:

If Dir$(&quot;C:\Program Files\Windows Media Player\wmplayer.exe&quot;) <> &quot;&quot; Then
'Do nothing
Else
MsgBox &quot;You need media player to run this program&quot;
Unload Me
End If -
radium.gif

Looking Toward The Future
 
I actually included the above code, so that you could actually find out why the program would hang. If oulook is non existant, it would err at the start, if the user was invalid it would fail at the logon, if the Outlook Program was closed it would fail in the middle. If the MAPI mail system is down it will fail at the end. All of these are trappable. Craig, mailto:sander@cogeco.ca
&quot;Procrastination is the art of keeping up with yesterday.&quot;
I hope my post was helpful!!!
 
Veg & Craigsander...

If the program you are looking for was not installed in the default location on the hard drive, then the above code will fail. What about searching the registry from your code instead, for a setting that only exists when the software is installed? Brett Birkett B.Comp
Systems Analyst
 
If the windows is not installed on c drive the above code will fail. What you can do is u can use winsyspath to determine the drive in which windows is installed and likewise you can find the program files folder and look for program which runs MS Outook.

From:
Apoorva Gala
You can mail me at apoo1972@rediffmail.com
 
Hi Gaff,

Try :-

Public Function AppExists(InAppExe As String) As Boolean
'----------------------------------------------------------
' Author: Codefish
'
' Date: 22/05/2000
'
' History:
'
' Purpose: - Checks to see whether a Application is
' installed on the machine.
'
' Notes: - Need Registry Access Functions Library
' (RegObj.dll) in project references.
'
' - InAppExe in the Form &quot;Excel.exe&quot;
'----------------------------------------------------------

'Declare Registry Object and Variables
Dim oReg As REGTool5.Registry
Dim bKeyFound As Boolean
Dim sValue As String

'Instantiate Registry Object
Set oReg = New REGTool5.Registry

sValue = &quot;&quot;

'Check Registry
bKeyFound = oReg.GetKeyValue(HKEY_LOCAL_MACHINE, _
&quot;Software\Microsoft\Windows\CurrentVersion\&quot; & _
&quot;App Paths\&quot; & InAppExe, &quot;Path&quot;, sValue)

'Return Result
If bKeyFound Then
AppExists = True
Else
AppExists = False
End If

'Release Reference
Set oReg = Nothing

End Function
 
Thank you all for your replies, they have all been very useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top