Double-click your software to open the file.
Author: Shuai hongjun
Unit shjassociatefiletype;
Interface
Uses Windows, registry;
{Associate the file type strfileextension with the program strexefilename, and strdiscription is a description of the file type}
Function assigntoprogram (const strfileextension, strdiscription, strexefilename: string): Boolean;
Implementation
{Associate the file type strfileextension with the program strexefilename, and strdiscription is a description of the file type}
Function assigntoprogram (const strfileextension, strdiscription, strexefilename: string): Boolean;
VaR
Regfile: Tregistry;
Begin
// Create a registry instance
Regfile: = Tregistry. Create;
With regfile do
Begin
// Set the root key value to hkey_classes_root.
Rootkey: = hkey_classes_root;
// Create or enable the auto-associated registration key for the extension
Openkey ('.' + strfileextension, true );
// Set automatic extension Association
Writestring ('', strfileextension + '_ auto_file ');
// Close the key
Closekey;
// Create or enable the auto-join key
Openkey (strfileextension + '_ auto_file', true );
// Set file type description
Writestring ('', strdiscription );
// Close the key
Closekey;
// Create or open the associated Program Key
Openkey (strfileextension + '_ auto_file \ shell \ open \ command', true );
// Set the associated Program (Note: Adding % 1 with double quotation marks can solve the problem of space in the file path)
Writestring ('', strexefilename + '" % 1 "');
// Close the key
Closekey;
// Open the default icon key
Openkey (strfileextension + '_ auto_file \ defaulticon', true );
// Associate the default icon
Writestring ('', strexefilename + ', 0 ');
// Release
Free;
Result: = true;
End;
End;
End.