Associate custom executable with file type in C#
]Associate a specific file extension with a custom executable in C#, allowing the user to start the executable with the associated file as a parameter when clicking on the file in File Explorer. In addition, you can also specify the desired icon for the file extension.
Solutions
While .NET does not provide an API to directly manage file associations, you can use the registry class to manipulate necessary key values.
Example of registry file associated with .txt with EmEditor:
][HKEY_CLASSES_ROOT\.txt]
@="emeditor.txt"
[HKEY_CLASSES_ROOT\emeditor.txt]
@="Text Document"
[HKEY_CLASSES_ROOT\emeditor.txt\DefaultIcon]
@="%SystemRoot%\\SysWow64\\imageres.dll,-102"
[HKEY_CLASSES_ROOT\emeditor.txt\shell]
[HKEY_CLASSES_ROOT\emeditor.txt\shell\open]
[HKEY_CLASSES_ROOT\emeditor.txt\shell\open\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" \"%1\""
[HKEY_CLASSES_ROOT\emeditor.txt\shell\print]
[HKEY_CLASSES_ROOT\emeditor.txt\shell\print\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" /p \"%1\""
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3