How to show the "Install Program Associations" window in Windows 8 / 8.1?

I want to show Set program associations[edit: for my program] windows, for example, Chrome, when it starts for the first time after installation, for example:

            enter image description here

He has:

  • The name of my program
  • File Types I want to install the default program (more than one)

How to do this with C # (or win32 C ++)?

Edit
I read some articles about changing the registry (using a .reg file or working with code to modify the registry) to set the program by default. It seems to work only on Windows XP / 7 or lower, not 8 / 8.1, since Microsoft uses a hash to protect the registry.

+4
source share
1

:

Windows, IApplicationAssociationRegistrationUI.

, "MyApp" :

class Program
{
    static void Main(string[] args)
    {
        IApplicationAssociationRegistrationUI app = (IApplicationAssociationRegistrationUI)new ApplicationAssociationRegistrationUI();
        int hr = app.LaunchAdvancedAssociationUI("MyApp");
        Exception error = Marshal.GetExceptionForHR(hr);
        if (error != null)
        {
            Console.WriteLine("Error: " + error.Message);
        }
    }
}

[Guid("1f76a169-f994-40ac-8fc8-0959e8874710")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IApplicationAssociationRegistrationUI
{
    [PreserveSig]
    int LaunchAdvancedAssociationUI([MarshalAs(UnmanagedType.LPWStr)] string pszAppRegName);
}

[ComImport]
[Guid("1968106d-f3b5-44cf-890e-116fcb9ecef1")]
public class ApplicationAssociationRegistrationUI
{
}

:-) , "MyApp" , . , :

1) "MyAppHTML" HKCR, :

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\MyAppHTML]
@="MyApp HTML Document"

[HKEY_CLASSES_ROOT\MyAppHTML\Application]
"ApplicationCompany"="Fictional Software Inc."

[HKEY_CLASSES_ROOT\MyAppHTML\shell]
@="open"

[HKEY_CLASSES_ROOT\MyAppHTML\shell\open]

[HKEY_CLASSES_ROOT\MyAppHTML\shell\open\command]
@="\"C:\\the app path\\testassoc.exe\""

2) "MyApp" ( HKCU, HKLM), "FictionalSoftware", , :

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\FictionalSoftware]

[HKEY_CURRENT_USER\Software\FictionalSoftware\MyApp]

[HKEY_CURRENT_USER\Software\FictionalSoftware\MyApp\Capabilities]
"ApplicationDescription"="My Fictional Application"

[HKEY_CURRENT_USER\Software\FictionalSoftware\MyApp\Capabilities\FileAssociations]
".htm"="MyAppHTML"
".html"="MyAppHTML"

3) Windows ( , HKCU HKLM), :

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\RegisteredApplications]
"MyApp"="Software\\FictionalSoftware\\MyApp\\Capabilities"

, , , . , - :

enter image description here

+6

Source: https://habr.com/ru/post/1584478/


All Articles