首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#设置开机启动项的有关问题

2012-09-09 
C#设置开机启动项的问题RegistryKey runKey Registry.LocalMachine.OpenSubKey(@SOFTWARE\Microsoft\Wi

C#设置开机启动项的问题
RegistryKey runKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
runKey.SetValue("test", Application.StartupPath + "WindowsFormsApplication1.exe");
runKey.Close();

我用的语句是这样的。现在问题是:
我在Form1_Load事件中去读取一个xml文件,开机启动时就报错误:不能在C:\...\..(这个路径忘记了,就是平时的系统路径)找到test.xml文件。有哪位大侠遇见过吗?教教我

[解决办法]
这个要看你的代码里是怎么取路径的。猜想是“当前路径”取的有问题,如果用
Environment.CurrentDirectory
有可能会取到windows\system32
建议这样取:
string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace("file://", "").Replace("file:\\","");

热点排行