Page 1 of 1
Programme Exists?
Posted: Fri Dec 02, 2016 7:46 am
by collectordave
Hi All
Is it possible, crossplatform, to silently check whether a programme has been installed?
For example I am using Open Office spreadsheets for reports and would like to know if the user has open Office installed when my programme starts.
Cheers
cd
Re: Programme Exists?
Posted: Fri Dec 02, 2016 10:38 am
by Marc56us
I do not think this type of information is available natively (windows) because most programs that do this type of verification take some time to do so.
This means that the program scans the entire disc.
This can go more or less quickly if the scanner is done starting with the most likely place.
For example, on Windows, start scan in %ProgramFile%
On Linux you can call 'locate' or 'whereis' to go faster.

Re: Programme Exists?
Posted: Fri Dec 02, 2016 11:31 am
by Dude
On Windows, you can easily find the executable that's responsible for launching any given file extension (eg. ".txt" reports "Notepad.exe" on my PC), but is that reliable enough for you?
Re: Programme Exists?
Posted: Fri Dec 02, 2016 2:55 pm
by collectordave
Hi
yes just need to know that a programme to edit .ods files exists i.e. open office.
Cheers
cd
Re: Programme Exists?
Posted: Fri Dec 02, 2016 4:20 pm
by TI-994A
collectordave wrote:...just need to know that a programme to edit .ods files exists i.e. open office.
Hi Dave. The only way to do that would be to check the registry root for that file extension,
(.ods), and determine if any applications have registered themselves as supporting it.
If the extension has not been registered, it's quite safe to say that none of the installed applications could officially open such a document. However, even if it has been registered by some application, there is no guarantee that the application is still installed, as some delinquent uninstallers sometimes fail to completely purge such file associations.
So, technically, there is no surefire way of determining this.
Re: Programme Exists?
Posted: Fri Dec 02, 2016 11:42 pm
by Dude
collectordave wrote:just need to know that a programme to edit .ods files exists i.e. open office.
Here's a procedure that I use to find out which executable opens a given doc:
Code: Select all
Procedure.s ExeForDoc(doc$)
doc$=LCase(doc$)
If FileSize(doc$)=-1
doc$=GetTemporaryDirectory()+Chr(160)+"."+GetExtensionPart(doc$)
f=CreateFile(#PB_Any,doc$) : If f : CloseFile(f) : tmp=1 : EndIf
EndIf
exe$=Space(999) : FindExecutable_(GetFilePart(doc$),GetPathPart(doc$),@exe$)
long$=Space(999) : GetLongPathName_(exe$,@long$,990)
If LCase(exe$)=doc$ Or LCase(long$)=doc$ : exe$="" : EndIf ; Not a document.
If tmp=1 : DeleteFile_(doc$) : EndIf
ProcedureReturn exe$
EndProcedure
Debug ExeForDoc("dummy.jpg") ; Shows which exe opens JPEG images.
Re: Programme Exists?
Posted: Sat Dec 03, 2016 4:25 am
by TI-994A
Dude wrote:Code: Select all
FindExecutable_(GetFilePart(doc$),GetPathPart(doc$),@exe$)
Nice one! Just tested it with orphaned file extensions in the registry, and it seems to work.
Some points to consider; the function only matches the file extension to an installed application that claims to support the file type, without verifying if it is actually able to open such a file. Furthermore, even if it is able to open it, it might simply be a reader of some sort, without the ability to edit the file.
Re: Programme Exists?
Posted: Sat Dec 03, 2016 4:33 am
by Dude
Yes, it only shows which exe
opens a doc. I never said
edits a doc.

Re: Programme Exists?
Posted: Sat Dec 03, 2016 5:46 am
by collectordave
Thanks for the procedure Dude and thanks for the advice TI-994A sage been caught with uninstallers before.
Will this work on the MAC as well? Sorry to ask not much time at the moment picking olives.
Regards
cd
Re: Programme Exists?
Posted: Sat Dec 03, 2016 6:14 am
by chi
less code, same result
Code: Select all
#ASSOCSTR_COMMAND = $1
#ASSOCF_ISPROTOCOL = $1000
pcchOut = #MAX_PATH
pszOut$ = Space(pcchOut)
If AssocQueryString_(#ASSOCF_ISPROTOCOL, #ASSOCSTR_COMMAND, @".ods", @"open", @pszOut$, @pcchOut) = #S_OK
RunProgram(ReplaceString(pszOut$, "%1", "C:\office.ods"))
EndIf
Will this work on the MAC as well?
nope, only works on windows
Re: Programme Exists?
Posted: Sat Dec 03, 2016 9:05 am
by Dude
chi wrote:less code, same result

Not so fast! Your code will need extra coding because you'll need to strip different flags from the end of the result for every single executable result.
For example, look at the outputs of these:
Code: Select all
#ASSOCSTR_COMMAND = $1
#ASSOCF_ISPROTOCOL = $1000
pcchOut = #MAX_PATH
pszOut$ = Space(pcchOut)
AssocQueryString_(#ASSOCF_ISPROTOCOL, #ASSOCSTR_COMMAND, @".doc", @"open", @pszOut$, @pcchOut)
Debug pszOut$ ; "C:\Program Files (x86)\Microsoft Office\OFFICE11\WINWORD.EXE" /n /dde
AssocQueryString_(#ASSOCF_ISPROTOCOL, #ASSOCSTR_COMMAND, @".txt", @"open", @pszOut$, @pcchOut)
Debug pszOut$ ; C:\Windows\system32\NOTEPAD.EXE %1
AssocQueryString_(#ASSOCF_ISPROTOCOL, #ASSOCSTR_COMMAND, @".xls", @"open", @pszOut$, @pcchOut)
Debug pszOut$ ; "C:\Program Files (x86)\Microsoft Office\OFFICE11\EXCEL.EXE" /e
AssocQueryString_(#ASSOCF_ISPROTOCOL, #ASSOCSTR_COMMAND, @".jpg", @"open", @pszOut$, @pcchOut)
Debug pszOut$ ; "C:\Programs\IrfanView\i_view32.exe" "%1"
So there's 4 very different flag parameters that you'll need to strip out of each result (ReplaceString won't do it). Are you going to code that for every exe in existence?

Re: Programme Exists?
Posted: Mon Dec 05, 2016 1:17 pm
by chi
maybe this fits better?
Code: Select all
#ASSOCSTR_COMMAND = $1
#ASSOCF_ISPROTOCOL = $1000
pcchOut = #MAX_PATH
pszOut$ = Space(pcchOut)
If AssocQueryString_(#ASSOCF_ISPROTOCOL, #ASSOCSTR_COMMAND, @".txt", @"open", @pszOut$, @pcchOut) = #S_OK
Debug StringField(GetPathPart(pszOut$)+GetFilePart(pszOut$), 1, "%1")
EndIf
Re: Programme Exists?
Posted: Mon Dec 05, 2016 1:51 pm
by Dude
That's better! Good thinking.

Re: Programme Exists?
Posted: Mon Dec 05, 2016 2:08 pm
by chi
Whew
