Finding the default application for opening a particular file type on Windows
You can check under registry section HKEY_CLASSES_ROOT
for the extension and action details. Documentation for this is on MSDN. Alternatively, you can use the IQueryAssociations interface.
How to get the default application mapped to a file extention in windows using Python
The registry isn't a simple well-structured database. The Windows
shell executor has some pretty complex logic to it. But for the simple cases, this should do the trick:
import shlex
import winreg
def get_default_windows_app(suffix):
class_root = winreg.QueryValue(winreg.HKEY_CLASSES_ROOT, suffix)
with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r'{}\shell\open\command'.format(class_root)) as key:
command = winreg.QueryValueEx(key, '')[0]
return shlex.split(command)[0]
>>> get_default_windows_app('.pptx')
'C:\\Program Files\\Microsoft Office 15\\Root\\Office15\\POWERPNT.EXE'
Though some error handling should definitely be added too.
How to launch default application for an arbitrary file in .net?
Just use Process.Start
(MSDN-article)
Process.Start(pathToYourFile);
Windows will launch the appropriate application. Just watch out: Up until Windows 8, this will throw an exception, if there is no standard application for that file type.
Java Find default desktop application for extension
I found the entries for user defined applications in the registry. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts.
I then loaded all these entries from the registry and grabbed what I needed.
Determine default program to open given file extension - VBS
I ultimately decided to use the assoc
and ftype
commands just in case we want to use this script on any other Windows versions. Here's a function that will do everything I needed. I hope it's helpful to someone!
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
' Should supply the program extension with period "." included
Function GetProgramPath(ext)
Dim strProg, strProgPath
' Get Program Association Handle
Set oExec = WshShell.Exec("cmd.exe /c assoc " & ext)
strProg = oExec.StdOut.ReadLine()
strProg = Split(strProg, "=")(1)
' Get Path To Program
Set oExec = WshShell.Exec("cmd.exe /c ftype " & strProg)
strProgPath = oExec.StdOut.ReadLine()
strProgPath = Split(strProgPath, """")(1)
' Return the program path
GetProgramPath = strProgPath
End Function
strPath = GetProgramPath(".doc")
WScript.Echo strPath
Use a Java application as the Default Program for a particular file type?
The problem is that a JAR file is selected as the "default application". However, JAR files are normally not executable. That is, a JAR file is not a valid Windows application. It doesn't matter if the JAR extension itself has a default application associated with it, because the "Open verb" is not used recursively in other "Open verb" definitions.
Instead,
- Create a batch (".BAT") file (or small EXE wrapper) that calls
java
(orjavaw
, as appropriate) and use that executable wrapper as the "Open with" program. (This will have an annoying intermediate console window if using a batch file.) Or, - Modify the registry so that the "Open verb" for the extension launches the JAR through
java
(orjavaw
).
In the end, either form should look similar to: javaw -jar TheJarFile.jar "%1%"
. (Note that javaw
is an executable, while TheJarFile.jar
is not an executable.)
See java - the Java application launcher for how to use java/javaw.
c# open file with default application and parameters
If you want the file to be opened with the default application, I mean without specifying Acrobat or Reader, you can't open the file in the specified page.
On the other hand, if you are Ok with specifying Acrobat or Reader, keep reading:
You can do it without telling the full Acrobat path, like this:
using Process myProcess = new Process();
myProcess.StartInfo.FileName = "acroRd32.exe"; //not the full application path
myProcess.StartInfo.Arguments = "/A \"page=2=OpenActions\" C:\\example.pdf";
myProcess.Start();
If you don't want the pdf to open with Reader but with Acrobat, chage the second line like this:
myProcess.StartInfo.FileName = "Acrobat.exe";
You can query the registry to identify the default application to open pdf files and then define FileName on your process's StartInfo accordingly.
Follow this question for details on doing that: Finding the default application for opening a particular file type on Windows
Related Topics
How to Seed a Random Class to Avoid Getting Duplicate Random Values
Allowing Untrusted Ssl Certificates with Httpclient
Changing the User Agent of the Webbrowser Control
What Exactly Are Unmanaged Resources
Web Reference VS. Service Reference
Can Console.Clear Be Used to Only Clear a Line Instead of Whole Console
How to Get the Public Ip Address of a User in C#
When Should "Sqldbtype" and "Size" Be Used When Adding SQLcommand Parameters
Catch Exception That Is Thrown in Different Thread
How to Serialize/Deserialize to 'Dictionary<Int, String>' from Custom Xml Not Using Xelement
What Does the '=>' Syntax in C# Mean
Asynchronous Locking Based on a Key
View/Edit Id3 Data for Mp3 Files
Get Last 10 Lines of Very Large Text File > 10Gb