做了一个Windows服务,写的逻辑代码是取浏览器的历史记录,在WinForm窗体程序运行就可以取到这个记录,但是同样的逻辑写在Windows服务里运行后,就没有取到这个记录,原因是什么?是不是它们运行的机制不一样?如何解决这个问题?

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace monitor
    {
        public class Monitor
        {
            System.Timers.Timer timer_GetURLHistory = new System.Timers.Timer();        public void TimerInit()
            {
                setting = sqliteHelper_AppSetting.ExecuteDataRow(string.Format(@"SELECT GetURLHistoryTime FROM Setting WHERE  Mac='{0}'", GetNetCardMacAddress()));            timer_GetURLHistory.Elapsed += new System.Timers.ElapsedEventHandler(timer_GetURLHistory_Tick);
                timer_GetURLHistory.Interval = Convert.ToInt32(setting["GetURLHistoryTime"]) * 1000;
                timer_GetURLHistory.Start();
            }        private void timer_GetURLHistory_Tick(object sender, EventArgs e)//读取浏览器历史记录
            {
                #region 扫描浏览器记录
                RegistryKey historykey;
                historykey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\TypedURLs", true);
                string historys = "";
                if (historykey != null)
                {
                    string[] names = historykey.GetValueNames();
                    foreach (String str in names)
                    {
                        historys += historykey.GetValue(str).ToString() + "\n";
                    }
                }
                #endregion
                #region 将扫描的浏览器历史信息存储入数据库
                if (historys == "")
                    return;
                //写入数据库
                #endregion
            }    }
    }
      

  2.   

    这个是逻辑代码,在WinForm程序中就可以将记录写入到数据库中,而在服务里运行时就无法取到!
    调用方法都是一致的,实例化Monitor,然后调用TimerInit()方法。
      

  3.   

    初步没看出什么问题,自己在Service里跟一下吧————使用Service的debugThread,执行OnStart(null)就行。
      

  4.   


    http://www.xiaozhou.net/cooldog/article/DotNet/149.htm
    http://www.xiaozhou.net/cooldog/article/VC/139.htm
      

  5.   

    http://www.cnblogs.com/xzwplus/archive/2008/03/30/1129452.html
      

  6.   


    LocalSystam 有什么问题么?