2
我有相关的我的程序使用此方法:C#总是0参数
public static void CreateFileAssociation(string extension, string key, string description, string path)
{
RegistryKey classes = Registry.ClassesRoot;
RegistryKey extensionKey = classes.CreateSubKey(extension);
extensionKey.SetValue(null, key);
RegistryKey typeKey = classes.CreateSubKey(key);
typeKey.SetValue(null, description);
RegistryKey shellKey = typeKey.CreateSubKey("shell");
RegistryKey shellOpenKey = shellKey.CreateSubKey("open");
RegistryKey shellOpenCommandKey = shellOpenKey.CreateSubKey("command");
shellOpenCommandKey.SetValue(null, path);
}
我Program.cs
:
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(args.TryGet(0)));
}
而且我Form1.cs
:
string filenameArg = "";
public Form1(string arg)
{
InitializeComponent();
filenameArg = arg;
}
当我打开我的相关文件(扩展名),我的程序以无参数启动
不知道这是什么问题。它出什么问题了 ?
您忘了向我们展示最重要的部分:当您将它写入注册表时,'path'里面有什么? –
我的应用程序是外部的,意味着它可以从任何地方运行,所以我总是在启动时将它复制到appdata \ local \ myProgram 所以路径是:... appdata \ local \ myProgram \ prog.exe – alix54
您在program.cs中显示string [] args; args.TryGet(0); string []在string []中没有定义TryGet方法?我正在用c#6.0来检查这个问题 –