How to associate a certain file type for my application?

Rohan Pande 445 Reputation points
2023-12-14T11:15:46.3766667+00:00

Hi,

I have an application that is being purely written in C++ and I want to associate a file type of a certain extension like ('.xyz').

Requirement is that if I double click on a '.xyz' file if my application is available, it should launch my application irrespective my application is running or not.

I have looked through some documentation, but I wasn't understanding much about it. There it was talking about ProgIDs. I am new to this so couldn't understand it properly and wasn't able to try it out.

Reference links that I have gone through:

  1. https://learn.microsoft.com/en-us/windows/win32/shell/how-to-register-a-file-type-for-a-new-application
  2. https://learn.microsoft.com/en-gb/windows/win32/shell/fa-sample-scenarios

Can someone help me in this? Thanks in advance.

Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,686 Reputation points
    2023-12-14T12:25:45.5333333+00:00

    I don't have Windows 11, but on Windows 10 a simple way is with

    HKEY_CLASSES_ROOT\.xyz\shell\open\command

    with for example, for a test :

    "E:\Sources\Test7\Debug\test7.exe" "%1"

    =>

    User's image


1 additional answer

Sort by: Most helpful
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2023-12-14T12:27:26.88+00:00

    Hi, Rohan Pande

    Add the .xyz key in registry root:
    Computer\HKEY_CLASSES_ROOT\.xyz
    Change the key's default value to your app name.

    User's image

    Then add sub keys below:
    User's image

    Modify the command's default value.
    Such as :

    "XXX\yourapp.exe" "%1"
    

    Use CMD to notify the system:

    assoc .xyz=your app's name
    

    enter image description here Sample:

    enter image description here

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.