gpt4 book ai didi

c# - 使用注册表值启动应用程序?它出什么问题了? .net 2.0 ONLY 请

转载 作者:行者123 更新时间:2023-11-30 17:21:30 24 4
gpt4 key购买 nike

我正在尝试编写一小段代码来检索应用程序的安装路径,并使用它 + 应用程序名称在单击时启动应用程序。这是我到目前为止所拥有的,但我不断收到错误“对象引用未设置为对象的实例”。这是我正在尝试使用的代码,有什么问题吗?

RegistryKey Copen = Registry.LocalMachine.OpenSubKey(@"Software\ComodoGroup\CDI\1\");
Copen.GetValue("InstallProductPath");
System.Diagnostics.Process.Start(Copen + "cfp.exe");

最佳答案

您实际上并没有存储正在检索的值。试试这个:

RegistryKey Copen = Registry.LocalMachine.OpenSubKey(@"Software\ComodoGroup\CDI\1\", RegistryKeyPermissionCheck.ReadSubTree);
if(Copen != null)
{
object o = Copen.GetValue("InstallProductPath");
if(o != null)
{
System.Diagnostics.Process.Start(IO.Path.Combine(o.ToString(), "cfp.exe"));
}
else
MessageBox.Show("Value not found");
}
else
MessageBox.Show("Failed to open key");

已编辑:也像 Martin 提到的那样检查 NULL

关于c# - 使用注册表值启动应用程序?它出什么问题了? .net 2.0 ONLY 请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3369340/

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