使用c#注册表的附加参数

时间:2012-08-18 04:28:05

标签: c#

这是我目前的代码:

RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                registryKey.SetValue("Programname", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));

没有错误或任何与此有关但是它没有指向我的程序。而是Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)指向我的AppData文件夹(如预期的那样)。但是我怎么想把它指向该文件夹中的可执行文件?

我正在使用C#2.0

1 个答案:

答案 0 :(得分:0)

你需要使用

System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName

OR

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase

获取路径..

所以它会是:

RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                registryKey.SetValue("Programname", System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);