求助:Windows Service 读取注册表键值

最近项目需要程序监控记录用户使用和打开的文件,于是做了一个使用Windows Service监控Recent文件夹中文件增加和更改的程序,

但是需要在服务程序确定Recent文件夹的路径,使用RegistryKey读取HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders\\Recent的键值,但是VS2010测试项目中读取的值和Windows Service读取的值不相同,

测试项目中读取的值是:C:\Users\Seariver\AppData\Roaming\Microsoft\Windows\Recent

而Windows Service程序中读取的值是:C:\Windows\system32\config\systemprofile\AppData\Roaming\Microsoft\Windows\Recent

小弟纠结了良久,在网上查了不少资料,但还是没弄明白怎么回事,也没有解决办法!求各位大虾指点迷津!

PS:

使用注册表查看该键值,发现和测试项目中读取的值是相同的;

上代码:读取注册表键值类

 1 internal class SystemDataCollecter
2 {
3 static internal readonly SystemDataCollecter Instrance=new SystemDataCollecter();
4 private SystemDataCollecter()
5 {
6 GenericRecentFolder();
7 }
8 private string recentFolder;
9 public string RecentFolder
10 {
11 get
12 {
13 return this.recentFolder;
14 }
15 }
16 public void GenericRecentFolder()
17 {
18 string path_recent = "";
19 RegistryKey key = Registry.CurrentUser;
20 //打开对应的注册表项,并获取Recent键的值,这个是用来寻找最近使用文件夹的路径。
21 path_recent = key.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders").GetValue("Recent").ToString();
22 recentFolder = path_recent + "\\";
23 }
24 }

posted on 2011-10-18 11:25  Seariver Coding  阅读(366)  评论(0编辑  收藏  举报

导航