為什么下面的語名在服務中不能執行﹖(服務本身沒有問題﹐能正常運行)
System.Diagnostics.Process.Start("IEXPLORE.exe","www.163.com");怎樣才能在服務中定時自動訪問綱站﹖如果實在不行﹐有沒有方法通過Windows服務,在局域外內取得路由器的外綱IP﹐并發送到指定的綱站﹖
System.Diagnostics.Process.Start("IEXPLORE.exe","www.163.com");怎樣才能在服務中定時自動訪問綱站﹖如果實在不行﹐有沒有方法通過Windows服務,在局域外內取得路由器的外綱IP﹐并發送到指定的綱站﹖
另外一定要勾上“允许服务与桌面交互”这个选项,已测试成功运行。
你的可以運行﹖﹖ 沒有道理啊﹗ System.Diagnostics.Process.Start("www.163.com")在Winform中沒有錯﹐在Windows服務中報錯。
如果用System.Diagnostics.Process.Start("IEXPLORE.exe","www.163.com")不會出錯﹐但是根本打不開綱站
protected override void OnStart(string[] args)
{
// TODO: 在此加入啟動服務的程式碼。
pSec = 0;
tm.Enabled = true;
}
/// <summary>
/// 停止這項服務。
/// </summary>
protected override void OnStop()
{
// TODO: 在此加入停止服務所需執行的終止程式碼。
tm.Enabled = false;
} private void Send()
{
try
{
System.Diagnostics.Process.Start("IEXPLORE.exe","www.163.com");
}
catch(System.Exception err)
{
System.IO.FileStream strm=new System.IO.FileStream("C:\\SendIPError.txt",System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write);
byte[] buf=System.Text.Encoding.Default.GetBytes(err.StackTrace + "\r\n" + err.Message);
strm.Write(buf,0,buf.Length);
strm.Close();
}
} private void tm_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
pSec +=1;
if(pSec>120)
{
pSec = 0;
Send();
}
}
第一:安装的时候不要让服务自动启动。
第二:安装后勾上“允许服务与桌面交互”这个选项。
第三:启动服务。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Windows.Forms;namespace UpdateService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
} protected override void OnStart(string[] args)
{ timer2.Enabled = true; } protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
private void Run()
{
try
{ System.Diagnostics.Process.Start("www.163.com");
}
catch (Exception eee)
{
Func.Msg(eee.Message);
}
} private void timer2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Run();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
private Thread MainThread;
public Service1()
{
InitializeComponent();
MainThread = new Thread(new ThreadStart(ThreadFunc));
MainThread.Priority = ThreadPriority.Lowest;
} protected override void OnStart(string[] args)
{
MainThread.Start();
}
public static void ThreadFunc()
{
while (true)
{
System.Threading.Thread.Sleep(10000); System.Diagnostics.Process.Start("IEXPLORE.exe", "www.163.com");
}
}
protected override void OnStop()
{
MainThread.Abort();
}
}
}
難道是版本問題﹖我用的是VS2003,FrameWork1.1.
已經勾上“允许服务与桌面交互”这个选项﹐但就是執行不了IE,實在沒法了
ASP.NET 状态服务
Remote Procedure Call (RPC) (默认是已启动不可选)
Remote Procedure Call (RPC) Locator安装以下补丁:
windows installer 3.1新建一个拥有administror权限的帐号程序重编译
重新安装windows服务
勾上“允许服务与桌面交互”这个选项
启动服务。最后试了一下,删除新建的帐号和服务后同样能运行,问题应该出在windows installer 3.1这里。
你在网站上建立一个WebService,调用这个WebService,让着个WebService返回IP地址即可
=========
我的網站是動態的IP啊﹐WebService只能建立在公司的綱站上﹐直接通過WebService怎么返回自已綱站的IP? 我是通過用在公司的放一個綱頁﹐然后訪問綱頁后﹐由綱頁取得IP﹐并保存,再由WebServies取出。