How to change filetype association in the registry?

后端 未结 4 595
眼角桃花
眼角桃花 2020-12-01 14:56

first time posting in StackOverflow. :D I need my software to add a couple of things in the registry.

My program will use

Process.Star

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 15:37

    Use the Registry class in Microsoft.Win32.

    Specifically, you want the ClassesRoot property of Registry to access the HKEY_CLASSES_ROOT key (cf. Understanding MS Windows File Associations and HKEY_CLASSES_ROOT: Core Services).

    using Microsoft.Win32;
    Registry
        .ClassesRoot
        .CreateSubKey(".smc")
        .SetValue("", "SMC", RegistryValueKind.String);
    Registry
        .ClassesRoot
        .CreateSubKey("SMC\shell\open\command")
        .SetValue("", "SMCProcessor \"%1\"", RegistryValueKind.String);
    

    Replace "SMCProcessor \"%1\"" with the command-line path and argument specification for the program that you wish to associate with files with extension .smc.

    But, instead of messing with the registry, why not just say

    Process.Start("SMCProcessor blblabla.smc");
    

提交回复
热议问题