Programme Exists?

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Programme Exists?

Post 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
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.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Programme Exists?

Post 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.

:wink:
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Programme Exists?

Post 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?
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Programme Exists?

Post by collectordave »

Hi

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.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Programme Exists?

Post 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.
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 :D
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Programme Exists?

Post 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.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Programme Exists?

Post 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.
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 :D
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Programme Exists?

Post by Dude »

Yes, it only shows which exe opens a doc. I never said edits a doc. :)
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Programme Exists?

Post 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
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.
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Programme Exists?

Post 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
Et cetera is my worst enemy
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Programme Exists?

Post 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. :twisted:

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? ;)
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Programme Exists?

Post 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
Last edited by chi on Mon Nov 27, 2017 6:33 pm, edited 1 time in total.
Et cetera is my worst enemy
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Programme Exists?

Post by Dude »

That's better! Good thinking. :)
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Programme Exists?

Post by chi »

Whew :wink:
Et cetera is my worst enemy
Post Reply