gpt4 book ai didi

C# 总是 0 个参数

转载 作者:行者123 更新时间:2023-11-30 20:31:59 25 4
gpt4 key购买 nike

我已将我的程序与此方法相关联:

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;
}

当我打开我的关联文件(扩展名)时,我的程序开始时没有参数

不知道这个有什么问题。有什么问题吗?

最佳答案

您可能在命令值中遗漏了 %1:

HKEY_CLASSES_ROOT\...\shell\open\command = ...appdata\local\myProgram\prog.exe "%1"

%1 替换为您选择的文件的路径。将它放在双引号中,这样带有空格的路径也可以作为单个参数传递。

关于C# 总是 0 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42267389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com