Programme Exists?
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Programme Exists?
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
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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: Programme Exists?
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.

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?
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?
-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Programme Exists?
Hi
yes just need to know that a programme to edit .ods files exists i.e. open office.
Cheers
cd
yes just need to know that a programme to edit .ods files exists i.e. open office.
Cheers
cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: Programme Exists?
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.collectordave wrote:...just need to know that a programme to edit .ods files exists i.e. open office.
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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Programme Exists?
Here's a procedure that I use to find out which executable opens a given doc:collectordave wrote:just need to know that a programme to edit .ods files exists i.e. open office.
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?
Nice one! Just tested it with orphaned file extensions in the registry, and it seems to work.Dude wrote:Code: Select all
FindExecutable_(GetFilePart(doc$),GetPathPart(doc$),@exe$)
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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: Programme Exists?
Yes, it only shows which exe opens a doc. I never said edits a doc. 

-
- Addict
- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Programme Exists?
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
Will this work on the MAC as well? Sorry to ask not much time at the moment picking olives.
Regards
cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: Programme Exists?
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
nope, only works on windowsWill this work on the MAC as well?
Et cetera is my worst enemy
Re: Programme Exists?
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.chi wrote:less code, same 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"

Re: Programme Exists?
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
Last edited by chi on Mon Nov 27, 2017 6:33 pm, edited 1 time in total.
Et cetera is my worst enemy
Re: Programme Exists?
That's better! Good thinking. 
