【发布时间】:2023-08-27 04:49:01
【问题描述】:
所以我制作了一个程序,在 pc 上创建一个注册表项,它添加了一个选项来将您的文件推送到您的设备。 (程序本身会将文件推送到您的 Android sd 卡。)
一旦我弄清楚了这个问题,一切都会运行良好,或者至少应该运行良好。当我右键单击一个项目并选择我的命令(即用我的程序打开)时,我的程序只是打开了,但没有传递任何参数。
一个月前,我设计了一个程序,当用户双击(只是双击,而不是右键单击上下文菜单)文件时打开,它打开了特定的程序,从那里我能够获取参数.
为什么我不能从上下文菜单中?
谢谢,很抱歉发了这么长的帖子。
这是我的部分代码:
private void Form1_Load(object sender, EventArgs e)
{
string c = textBox3.Text;
string[] args = System.Environment.GetCommandLineArgs();
try
{
string location = args[1];
MessageBox.Show(location);
//For testing purposes only
Properties.Settings.Default.thinglocation = location;
Properties.Settings.Default.Save();
Process();
}
catch
{
}
这是注册表代码。顺便说一句,字符串 c 是“C:\File push.exe”我程序的位置。
string MenuName = "*\\shell\\NewMenuOption";
string Command = "*\\shell\\NewMenuOption\\command";
RegistryKey regmenu = null;
RegistryKey regcmd = null;
try
{
regmenu = Registry.ClassesRoot.CreateSubKey(MenuName);
if (regmenu != null)
regmenu.SetValue("", "Push to Android");
regcmd = Registry.ClassesRoot.CreateSubKey(Command);
if (regcmd != null)
regcmd.SetValue("", c +"%1");
}
catch (Exception ex)
{
MessageBox.Show(this, ex.ToString());
}
finally
{
if (regmenu != null)
regmenu.Close();
if (regcmd != null)
regcmd.Close();
【问题讨论】:
-
您需要向我们展示您创建的注册表项,并且可能需要将 %1 添加到该注册表项
-
您是否检查了“EventArgs e”或“string[] args”中的值?我建议检查项目的属性(如文件名)是否是集合的一部分。