Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've created a new file type containing spaces and have specified the open command for it:

assoc .php="PHP Script"
ftype "PHP Script"="c:\program files (x86)\php\php.exe" -f "%1" -- %~2

So far so good, but now I'm unable to check which command is used to open files of this type:

ftype "PHP Script"
File type 'PHP' not found or no open command associated with it.

I've tried using the caret symbol, to no effect. How do I get ftype to accept spaces for retrieving the command currently in use?

share|improve this question
    
+1, interesting question! I didn't even know ProgIDs could contain spaces before this. –  Karan Jun 9 '13 at 19:26

1 Answer 1

up vote 3 down vote accepted

You're doing it wrong. First, some background reading on MSDN:

When you use assoc .ext=fileType, that fileType is actually the ProgID. As the last link above states:

The proper format of a ProgID key name is [Vendor or Application].[Component].[Version], separated by periods and with no spaces, as in Word.Document.6. The Version portion is optional but strongly recommended.

The file type description you can add as a FriendlyTypeName value in the registry.

For example:

[HKEY_CLASSES_ROOT\.txt]
@="txtfile"
"PerceivedType"="text"
"Content Type"="text/plain"

Here .txt is obviously the extension and the (Default) value is set to the ProgID i.e. txtfile.

[HKEY_CLASSES_ROOT\txtfile]
@="Text Document"
"FriendlyTypeName"="Text Document"

Here for the ProgID we have the (Default) value set to the file type description, and same for FriendlyTypeName. In general though the latter is used to display localised string resources and must be formatted as an indirect string (a fully qualified file name and resource value preceded by the @ symbol, for instance @%SystemRoot%\system32\notepad.exe,-469 for txtfile).


I don't know why assoc and ftype both allow you to use spaces in the fileType/ProgID strings, since that goes against MS' own guidelines. ProgIDs with spaces even work properly if created manually in the registry (I just tested), but significantly I found not a single ProgID created by any program that uses spaces. Stranger still is how ftype seems to reject spaces while getting data (quotes don't help), whereas it has no problems accepting them while setting the command string in the first place (quotes aren't even required while setting).

My guess is someone forgot to inform the ftype devs of this discrepancy, because I couldn't figure out a way to make the command retrieve the command string it had itself set previously for a ProgID containing spaces. My advice? Stick to the guidelines, don't use spaces in ProgIDs and save yourself the grief of trying to figure out Windows' quirks.

share|improve this answer
1  
+1. For the record, though, there's a workaround: ftype | findstr /c:"PHP Script" –  Harry Johnston Jun 9 '13 at 22:25
    
@HarryJohnston: Nice! Didn't even think of find/findstr, which of course will work since ftype by itself enumerates all the registered types. –  Karan Jun 9 '13 at 22:55
    
+1, nice work :T –  Endoro Jun 10 '13 at 0:11
    
or ftype | grep "PHP Script", if you have gnuwin installed. At least I can say that less is invaluable if working in windows' command line. –  x-yuri Jun 11 '13 at 12:18
    
It's too bad M$ doesn't give scripts that do it right, right out of the box. :( –  Adrian Jun 30 '13 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.