Tuesday 19 February 2019

windows 8.1 - How to bind a file type to be opened with command-line options?


I need to open files of type .unitypackage using the command Unity.exe -openfile "%1", but if I "right-click -> open with" it only allows me to select the program, not the command line options.


What can I do to fix that on Windows 8.1?



Answer



There are a few different options to set a file association in Windows 8. Unfortunately, the built-in methods tend not to support any fancy like custom command-line arguments.




  • You can right-click a file and select Open With, then Choose Default Program to browse for the program. You will likely need to manually edit the registry to add the -openfile switch.




  • You can set file associations with the Set Default Programs app; again you will need to manually modify the registry to include the switch.


    If you go this route, then you can do it as follows:



    1. Select Settings

    2. Type associate

    3. Select Change the file type associated with a file extension

    4. Select the file extension

    5. Click the [Change Program] button


    Note, you may not see the file extension in the list if you have not previously tried to open the file (for example with the previous method).




  • Use a third-party program like FileTypesMan to create a file association. With FileTypesMan, you could do it as so:



    1. Edit → New File Extension (or Ctrl+T)

    2. Fill out the dialog to create an extension .unitypackage: Screenshot of New File Extension dialog

    3. Actions → New Action (or Ctrl+N)

    4. Fill out the dialog: Screenshot of New Action dialog




  • Manually create the registry entries for the association. I’ve taken the liberty of whipping one up for you. Just copy it to a plain-text file, make sure to save it with an extension of .reg, not .reg.txt (you can do this by selecting All Files (*.*) in the file-type drop-down in the Save As dialog). Then run the saved registry script and accept to merge it. You can use hard-coded paths (which you can edit if needed in the text-editor) or use variables by uncommenting the specified lines (you would need to edit those in Regedit since they are encoded as hexadecimal).


    REGEDIT4

    [HKEY_CLASSES_ROOT\.unitypackage]
    @="UnityPackage"

    [HKEY_CLASSES_ROOT\UnityPackage]
    @="Unity Package"

    [HKEY_CLASSES_ROOT\UnityPackage\Shell\DefaultIcon]
    @="\"C:\\Program Files (x86)\\Unity\\Editor\\Unity.exe\",1"
    ; Uncomment the line below by removing the leading semi-colon to use an environment variable ("%ProgramFiles(x86)%\Unity\Editor\Unity.exe",1) instead of the hard-coded path above.
    ;@=hex(2):22,25,50,72,6f,67,72,61,6d,46,69,6c,65,73,28,78,38,36,29,25,5c,55,6e,69,74,79,5c,45,64,69,74,6f,72,5c,55,6e,69,74,79,2e,65,78,65,22,2c,31,00

    [HKEY_CLASSES_ROOT\UnityPackage\Shell\Open]
    @="&Open"

    [HKEY_CLASSES_ROOT\UnityPackage\Shell\Open\Command]
    @="\"C:\\Program Files (x86)\\Unity\\Editor\\Unity.exe\" -openfile \"%1\""
    ; Uncomment the line below by removing the leading semi-colon to use an environment variable ("%ProgramFiles(x86)%\Unity\Editor\Unity.exe") instead of the hard-coded path above.
    ;@=hex(2):22,25,50,72,6f,67,72,61,6d,46,69,6c,65,73,28,78,38,36,29,25,5c,55,6e,69,74,79,5c,45,64,69,74,6f,72,5c,55,6e,69,74,79,2e,65,78,65,22,20,2d,6f,70,65,6e,66,69,6c,65,20,22,25,31,22,00


(Note: I do not have Unity installed on my current machine, so I cannot check the icons included in the binary, so you may need to change the ,1 in the DefaultIcon settings in the registry script and dialogs to something more appropriate like ,3 or ,10 or something, if it doesn’t include any document icons at all, then either use ,0 or remove that part altogether.)


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...