Double-click your software to open the file.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.