# Getting Executable for File Extension

**URL:** <https://forums.powershell.org/t/getting-executable-for-file-extension/21406>\
**Category:** PowerShell Help\
**Created:** [January 19, 2023, 11:56am UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406 "2023-01-19T11:56:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Privacy](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Privacy](https://forums.powershell.org/u/Privacy)\
**Post date:** [January 19, 2023, 11:56am UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/1 "2023-01-19T11:56:54Z")

</div>

Hello, is there a cmdlet to get the executable for handling a specific File-Type

e.g. c:\ …\Liebreofice\writer.exe for file.odt ?

& - works but I need the path to the executable, because I want to use specific commandline parameters

Thank you  
Privacy

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 19, 2023, 1:08pm UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/2 "2023-01-19T13:08:48Z")

</div>

Privacy,  
Welcome to the forum. 👋🏽

> [@Privacy](#):
>
> is there a cmdlet to get the executable for handling a specific File-Type

AFAIK there is no built in cmdlet to determine the file type association of a given extension.

> [@Privacy](#):
>
> because I want to use specific commandline parameters

What would you like to accomplish? There might be another/better way.

---

<div class="post-metadata">

**Author:** ![Privacy](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Privacy](https://forums.powershell.org/u/Privacy)\
**Post date:** [January 19, 2023, 5:36pm UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/3 "2023-01-19T17:36:13Z")

</div>

I create a draft file (\*.odt) which should then be opened by libre-office and after editing the file should be moved and an pdf created and perhaps send by (hyla)-fax.

with

& file.odt  
libre\_office starts and the file can be edited - but the powershell script is not paused until libreoffice terminated.

Privacy

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 19, 2023, 9:26pm UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/4 "2023-01-19T21:26:26Z")

</div>

> [@Privacy](#):
>
> perhaps send by (hyla)-fax.

Wow, that sounds like a workflow from the 90’s. 🤭 Really? … fax? 🤨

> [@Privacy](#):
>
> which should then be opened by libre-office and after editing the file should be moved and an pdf created

That sounds like there is a lot of manual work involved. And since LibreOffice can export PDF files out of the box it might be a better option to use some Office internal automation instead of PowerShell.

Regardless of that - I still cannot see whatfor you need the path for the executable.

> [@Privacy](#):
>
> libre\_office starts and the file can be edited - but the powershell script is not paused until libreoffice terminated.

If that’s your issue you could simply add a loop checking for the process of LibreOffice and when the process is terminated you could continue your script. 🤷🏽‍♂️

---

<div class="post-metadata">

**Author:** ![Privacy](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@Privacy](https://forums.powershell.org/u/Privacy)\
**Post date:** [January 20, 2023, 12:40am UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/5 "2023-01-20T00:40:50Z")

</div>

The Script should work on different PC - and the Path to Libreoffice ist not the same in every PC.  
So I need the Name of the executable to look if the process terminated.

And yes - we use Fax, which works nice … and the script get’s a Patient and doctor ID and Fax or PDF as Parameter  
The iDs are used to create the filename - an at the end to move the file to an archive - or to cancel the file and delete the draft

Testing, whether the created file ist writeable would be an option …  
Invoke-Item doesn’t accept -WAIT and return nothing

Another option is to define ab Systemvarible “libreoffice” on each PC which points to the LO-Path  
Privacy

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [January 20, 2023, 2:14am UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/6 "2023-01-20T02:14:35Z")

</div>

The executable name should be the same or similar regardless of where it’s installed. You could simply query for existing instances and store that. Then launch libre and a new query should reveal the new process (compared to the list before) that you can wait until it’s gone. Otherwise this question should really be “how to find the install location of libre office”

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 20, 2023, 7:54am UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/7 "2023-01-20T07:54:05Z")

</div>

> [@Privacy](#):
>
> The Script should work on different PC - and the Path to Libreoffice ist not the same in every PC.

So we’re talking about a very heterogenous environment the script has to work on, right?

> [@Privacy](#):
>
> So I need the Name of the executable to look if the process terminated.

As far as I can remember has the name of the executable always been `soffice` because it started as “Star Office” once and kept the file name since then. 👆🏽 😉

> [@Privacy](#):
>
> And yes - we use Fax, which works nice

Please don’t get me wrong … I wasn’t complaining … I was wondering. 😉

> [@Privacy](#):
>
> an at the end to move the file to an archive - or to cancel the file and delete the draft

For me that sounds more and more like PowerShell isn’t the right tool for the job. 🤷🏽‍♂️

> [@Privacy](#):
>
> Testing, whether the created file ist writeable would be an option …  
> Invoke-Item doesn’t accept -WAIT and return nothing

Again … an `Invoke-Item` for the desired file, wait a few seconds for LibreOffice to start and then loop as long as the process “soffice” is running should do the trick, don’t you think?

> [@Privacy](#):
>
> Another option is to define ab Systemvarible “libreoffice” on each PC which points to the LO-Path  
> Privacy

> [@krzydoug](#):
>
> Otherwise this question should really be “how to find the install location of libre office”

Either you search for the file in the default locations `C:\Program Files` or `C:\Program Files (x86)` on the first run of the script and save the found path persistently on the computer - for example in the registry. Or you simply use the running process to get the info you’re after.

```auto
Get-Process soffice | Select-Object -Property Name, Path, CommandLine

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/getting-executable-for-file-extension/21406/8 "2024-05-16T20:16:05Z")

</div>


