关于Windows服务 做了一个Windows服务,写的逻辑代码是取浏览器的历史记录,在WinForm窗体程序运行就可以取到这个记录,但是同样的逻辑写在Windows服务里运行后,就没有取到这个记录,原因是什么?是不是它们运行的机制不一样?如何解决这个问题? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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 } }} 这个是逻辑代码,在WinForm程序中就可以将记录写入到数据库中,而在服务里运行时就无法取到!调用方法都是一致的,实例化Monitor,然后调用TimerInit()方法。 初步没看出什么问题,自己在Service里跟一下吧————使用Service的debugThread,执行OnStart(null)就行。 http://www.xiaozhou.net/cooldog/article/DotNet/149.htmhttp://www.xiaozhou.net/cooldog/article/VC/139.htm http://www.cnblogs.com/xzwplus/archive/2008/03/30/1129452.html LocalSystam 有什么问题么? t-sql,什么样的数据库 请教一个关于数字分隔的正则问题 Entity Framwork 4.1 问题? 请教下,网页上的button没有ID和name我怎么获取它啊 请教大家一个简单问题? C# 推荐一个vs2005的下载地址————速度很快——不要错过哦 怎样验证email winform怎么获取CMD输出值 , 怎么算比例(C#) 怎样在没有安装vs的电脑上运行C#程序啊? FileUpload如何显示原来保存的路径?
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
} }
}
调用方法都是一致的,实例化Monitor,然后调用TimerInit()方法。
http://www.xiaozhou.net/cooldog/article/DotNet/149.htm
http://www.xiaozhou.net/cooldog/article/VC/139.htm
LocalSystam 有什么问题么?