Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Nov 21, 2019 1:33 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Failed Launch Returns LastErrorCode 0
PostPosted: Mon Feb 27, 2012 10:20 pm 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
I have an application that launches a PDF help file from the menu, but in Windows 7, FolderItem.Launch returns a FolderItem.LastErrorCode of 0 if no PDF reader is installed on the system. Any recommendations as to how to check for a default application for PDF files prior to launch if a failed launch under this condition doesn't return a valid error code?

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Failed Launch Returns LastErrorCode 0
PostPosted: Tue Feb 28, 2012 8:25 am 
Offline

Joined: Wed May 20, 2009 4:43 pm
Posts: 958
capaho wrote:
I have an application that launches a PDF help file from the menu, but in Windows 7, FolderItem.Launch returns a FolderItem.LastErrorCode of 0 if no PDF reader is installed on the system. Any recommendations as to how to check for a default application for PDF files prior to launch if a failed launch under this condition doesn't return a valid error code?

This is what I have used, haven't checked it on Windows 7
Dim acrobatInstalled as Boolean
Dim r as RegistryItem
acrobatInstalled = true
#IF TargetWin32 THEN
Try
r = New RegistryItem("HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe", False)
Catch
'MsgBox "Failed to find Acrobat Reader."
acrobatInstalled = False
End Try
#ENDIF

_________________
RB 2009r4 Windows XP


Top
 Profile  
Reply with quote  
 Post subject: Re: Failed Launch Returns LastErrorCode 0
PostPosted: Tue Feb 28, 2012 8:59 am 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
Quote:
This is what I have used, haven't checked it on Windows 7
Dim acrobatInstalled as Boolean
Dim r as RegistryItem
acrobatInstalled = true
#IF TargetWin32 THEN
Try
r = New RegistryItem("HKEY_CLASSES_ROOT\Software\Adobe\Acrobat\Exe", False)
Catch
'MsgBox "Failed to find Acrobat Reader."
acrobatInstalled = False
End Try
#ENDIF

Thanks for the code snippet. I'll give it a try.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Failed Launch Returns LastErrorCode 0
PostPosted: Tue Feb 28, 2012 9:39 pm 
Offline

Joined: Fri Jul 21, 2006 12:28 am
Posts: 509
The code snippet solved the problem although I had to add an exception handler to trap a RegistryAccessErrorException that occurs if the application is not run as administrator.

_________________
Regards,
Carl
Capaho Web
http://www.capaho.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Failed Launch Returns LastErrorCode 0
PostPosted: Wed Feb 29, 2012 12:51 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
A little late, but here's another way:

Function FindDefaultApp(Extends documentFile As FolderItem) As FolderItem
//Given a documentFile FolderItem, will return a FolderItem corresponding to the application currently
//associated with the file (e.g. a .doc file might return C:\Program Files\Microsoft Office\winword.exe)
//If no application is associated with the documentFile, the documentFile doesn't exist, or is inaccessble
//then this function returns Nil.
//If the documentFile is itself an application (.exe, .scr, etc.) then this function returns a FolderItem
//corresponding to the documentFile itself (e.g. "C:\foo\bar.exe" is associated with itself.)

#If TargetWin32 Then
Declare Function FindExecutableW Lib "Shell32" (file As WString, directory As WString, result As Ptr) As Integer

Dim mb As New MemoryBlock(260)
If FindExecutableW(documentFile.AbsolutePath, Nil, mb) > 32 Then
Return GetFolderItem(mb.WString(0))
End If
#endif
End Function

_________________
Boredom Software


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group