[英]C# Always 0 Arguments
我已经将我的程序与此方法相关联:
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
将替换为所选文件的路径。 将其放在双引号中,这样带有空格的路径也将作为单个参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.