[英]C# Always 0 Arguments
I have associated my program with this method : 我已经将我的程序与此方法相关联:
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);
}
My Program.cs
: 我的
Program.cs
:
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(args.TryGet(0)));
}
And my Form1.cs
: 和我的
Form1.cs
:
string filenameArg = "";
public Form1(string arg)
{
InitializeComponent();
filenameArg = arg;
}
When i open my associated file(extension), My program starts with no arguments 当我打开关联的文件(扩展名)时,我的程序开始时没有参数
Don't know what's the problem with this. 不知道这是什么问题。 What's wrong with it ?
它出什么问题了 ?
You probably missed the %1
in your command value: 您可能错过了命令值中的
%1
:
HKEY_CLASSES_ROOT\...\shell\open\command = ...appdata\local\myProgram\prog.exe "%1"
The %1
is replaced by the path of the file you selected. %1
将替换为所选文件的路径。 Put it in double quotes so that paths with white spaces get passed as a single argument, too. 将其放在双引号中,这样带有空格的路径也将作为单个参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.