首页 新闻 会员 周边

C# 随系统启动而启动出现问题了(我只有四个园豆 不够给了 呵呵 还请大侠们 帮帮忙)

0
[已解决问题] 解决于 2012-03-02 11:20

我的机器是XP的,软件也在注册表里写成了自动启动,现在随系统启动后 问题出现了:

软件在D盘下 D:/test/test.exe 下面还有一个配置文件D:/test/test.xml

现在随系统启动后 找不到配置文件了 它指向的目录是 我的文档 很是疑惑啊

如果不是随系统启动 手动启动它 可以正确的读到配置文件

读取配置文件的方式是

string AppPath = Directory.GetCurrentDirectory();

string strXML = AppPath + @"\config.xml";

 

开机开机启动

private void autoRun(bool isRun)
{
string strKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
RegistryKey rekey = null;

try
{
rekey = Registry.CurrentUser.OpenSubKey(strKey, true);
if (rekey == null)
{
toolStripStatusLabel2.Text = "设置失败!";
return;
}

if (isRun)
{
string AppPath = getDir();
string runSoftDir = AppPath + @"\SuperAuto520.exe";
rekey.SetValue("SuperAuto520", runSoftDir);
toolStripStatusLabel2.Text = "软件自动启动开启!";
}
else
{
rekey.DeleteValue("SuperAuto520");
toolStripStatusLabel2.Text = "软件自动启动取消!";
}
}
catch (Exception ex)
{
toolStripStatusLabel2.Text = "设置失败!";
}
finally
{
rekey.Close();
}

}

 

现在软件是可以随系统启动 但是读不到配置文件 郁闷ing。。。。。

FiendReam的主页 FiendReam | 初学一级 | 园豆:8
提问于:2012-02-29 09:24
< >
分享
最佳答案
1

引用一篇文章,你看看是不是这个原因:System.IO.Directory.GetCurrentDirectory的注意事项

.Net Framework中,System.IO.Directory.GetCurrentDirectory()方法用于获得应用程序当前工作目录

如果使用此方法获得应用程序所在的目录,应该注意:System.IO.Directory.GetCurrentDirectory()方法获得的目录路径随着OpenFileDialog、SaveFileDialog等对象所确定的目录而改变(切换工作目录)

一般情况下,应该使用System.Windows.Forms.Application.StartupPath或System.AppDomain.CurrentDomain.BaseDirectory来获得应用程序所在的目录

artwl | 专家六级 |园豆:16736 | 2012-02-29 09:32

恩 我还想问的是 我一开机启动 我用FileStream去写日志到文件

fs = new FileStream(STR_FILENAME_LOG, FileMode.Append);
byte[] byteInfo = Encoding.Default.GetBytes(strDataTime);
// 写入自定义日志
fs.Write(byteInfo, 0, byteInfo.Length);
//清空缓冲区、关闭流
fs.Flush();
fs.Close();

但是开机没有打印日志 是怎么回事啊

FiendReam | 园豆:8 (初学一级) | 2012-03-01 18:10

@fiend: 不好意思哈,我winform程序写的不多,目前还没研究过这个问题

artwl | 园豆:16736 (专家六级) | 2012-03-02 08:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册