- 1 year ago
Obtain path to program associated with a file
To obtain the path to the program associated with a specific file on Windows, you can use the assoc
and ftype
commands in the Windows command prompt or PowerShell. Here's how you can do it:
Using the Command Prompt:
Open the Command Prompt.
Use the
assoc
command with the file extension to retrieve the associated file type. For example, to get the associated file type for a.txt
file, run:assoc .txt
The command will return the associated file type, such as
.txt=txtfile
.Once you have the associated file type, use the
ftype
command with the file type to retrieve the program associated with it. For example, to get the program associated with thetxtfile
file type, run:rustftype txtfile
The command will return the program path associated with the file type, such as
txtfile="%SystemRoot%\system32\NOTEPAD.EXE %1"
.
Using PowerShell:
Open PowerShell.
Use the
Get-Command
cmdlet with the file extension to retrieve the associated program. For example, to get the program associated with a.txt
file, run:powershellGet-Command -ErrorAction SilentlyContinue -Name 'file.txt' | Select-Object -ExpandProperty Definition
Replace
'file.txt'
with the path to the actual file you want to query.The command will return the program path associated with the file, such as
C:\Windows\System32\notepad.exe
.
These methods will help you retrieve the path to the program associated with a specific file on Windows. Keep in mind that the associated program may vary based on the file type and the user's configuration.