Your full service technology partner! 
-Collapse +Expand
Search Delphi Group:

-Collapse +Expand Delphi To/From
-Collapse +Expand Delphi Store

Prestwood eMagazine

July Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingDelphi for W...Using Data   Print This    All Groups  
  From the November 2010 Issue of Prestwood eMag
Delphi Using Data:
Set File Extension to Always Show in Explorer
Posted 17 years ago on 3/27/2003 and updated 6/8/2008
Take Away: The default setting in Windows Explorer is to always hide known file extensions. This Delphi code shows you how to programatically set your own extension to always show in Explorer.


The default setting in Windows Explorer for file extensions is to hide extensions of known file types.

Known file types are those extensions that are shown in the list of File Types in the Windows Explorer Options dialog.

But, let's say that you just built an application that uses a specific file extension for it's data files. Let's say the application is called PixieDust, and you use the .pxy file extension. You want this file extension to appear always, especially in "Open File" dialogs.

If you do this from Windows Explorer, you edit the File Type from Options/File Types, and set:

Description of Type: Pixie File
open=PixieDust.exe (of course, this would include the full path)
"Always show extension" is checked.

This last setting adds a Registry flag that will apply to all Windows users.

To programatically set this flag, here is a Delphi function that will update the Registry class for you:

unit ExtensionRegTest;


function CheckExtensionAlwaysShown:boolean;


Registry, ShlObj;

function CheckExtensionAlwaysShown:boolean;
winReg : TRegistry;
  KeyInfo : TRegKeyInfo;
  extClass : string;
  testFlag : boolean;
  extClass := '';
  keyFound := False;
  testFlag := True;
  winReg := TRegistry.Create(KEY_ALL_ACCESS);
    winReg.RootKey := HKEY_CLASSES_ROOT;
    // NOTE: It's a good idea to open this class key in read-only.
    //       We don't want to accidentally make changes to it!

    keyFound := winReg.OpenKeyReadOnly('.pxy');
    if keyFound then
      // Test to be sure it is a valid registry key that has values...
      keyFound := winReg.GetKeyInfo(KeyInfo);
      if keyFound then
        // this fetches the Class Name string assigned to the extension's key
        extClass := winReg.ReadString('');
    if keyFound then
      // NOTE: I ran into problems in trying to assign the 'AlwaysShowExt' attribute,
      //       until I discovered that opening HKEY_CLASSES_ROOT will ALWAYS set the
      //       access mode to Read-Only!  You have to do this to write a new value!
      winReg.Access := KEY_ALL_ACCESS;
      keyFound := winReg.OpenKey(extClass, False);
      // Test to be sure it is a valid registry key that has values...
      if keyFound then
        keyFound := winReg.GetKeyInfo(KeyInfo);
    if keyFound then
      // Look for the setting we're planning on applying.
      testFlag := winReg.ValueExists('AlwaysShowExt');
      if not testFlag then
        // First, make SURE that the following value is removed if it's there!
        testFlag := winReg.ValueExists('NeverShowExt');
        if testFlag then
          // NOTE: if we fail to delete the 'NeverShowExt', we don't want to
          //       add the 'AlwaysShowExt' by mistake!  So in the event of a
          //       delete failure, our testFlag will remain TRUE.
          if winReg.DeleteValue(CKEY_HIDE) then
            testFlag := False
            keyFound := False;
        if not testFlag then
          winReg.WriteString('AlwaysShowExt', '');
          keyFound := False;  // on exceptins, this will indicate an error
  if keyFound and (not testFlag) then
    // Finally, we want the Windows Explorer to realize we modified
    // our file type by using the SHChangeNotify API.
  Result := keyFound;



Share a thought or comment...
Comment 1 of 1


Thank you for the "File extensions" topic.

I wonder what the CKEY_HIDE constant is : your page is the only one that mentions it on the whole web.

Best regards,


Posted 13 years ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P125A1
Enter key:
KB Post Contributed By Scott Wehrly:

Scott Wehrly is currently working on .Net web applications for the gaming industry. Scott is a former employee of Prestwood Software (he was a Development Manager). Scott's specialties include C#, ASP.Net, MSSQL Server 2005, Delphi, SQL databases, C++, C, and Windows programming in general. When time allows, he participates in this online community.

Visit Profile

 KB Article #100217 Counter
Since 4/2/2008
Sales Website: Or visit our legacy sales site:

©1995-2020 Prestwood IT Solutions.   [Security & Privacy]