為什么下面的語名在服務中不能執行﹖(服務本身沒有問題﹐能正常運行)
System.Diagnostics.Process.Start("IEXPLORE.exe","www.163.com");怎樣才能在服務中定時自動訪問綱站﹖如果實在不行﹐有沒有方法通過Windows服務,在局域外內取得路由器的外綱IP﹐并發送到指定的綱站﹖

解决方案 »

  1.   

    System.Diagnostics.Process.Start("www.163.com");
    另外一定要勾上“允许服务与桌面交互”这个选项,已测试成功运行。
      

  2.   

    to: alldj(灵山妖姬) 
    你的可以運行﹖﹖ 沒有道理啊﹗ System.Diagnostics.Process.Start("www.163.com")在Winform中沒有錯﹐在Windows服務中報錯。
    如果用System.Diagnostics.Process.Start("IEXPLORE.exe","www.163.com")不會出錯﹐但是根本打不開綱站
      

  3.   

    我的代碼如下﹕
    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();
    }
    }
      

  4.   

    不知道你哪个环节出错,我同样是捕捉异常,用的timer控件,是可以成功运行的。
    第一:安装的时候不要让服务自动启动。
    第二:安装后勾上“允许服务与桌面交互”这个选项。
    第三:启动服务。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();
            }
        }
    }
      

  5.   

    启动前勾上“允许服务与桌面交互”这个选项,已测试成功运行。
    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();
            }
        }
    }
      

  6.   

    痛苦死了~~~~ 一樣的方法﹐昨就在我這里不行呢﹖
    難道是版本問題﹖我用的是VS2003,FrameWork1.1.
    已經勾上“允许服务与桌面交互”这个选项﹐但就是執行不了IE,實在沒法了
      

  7.   

    你的操作系统是不是win2000?如果是的话建议拿到xp上编译一下,2000下timer控件在windows服务里编程会有问题。
      

  8.   

    time控件是沒有問題﹐可以正常循環﹐我測試了﹐執行其它的方法沒有事(例如﹕訪問WebServies)﹐就是開不了IE.
      

  9.   

    初步找到原因,用.net03写的服务确实不行,用.net05写没问题。怀疑是和RPC的某些权限有关,正在解决中。
      

  10.   

    做了以下事情,问题解决,但不知道是通过哪一个环节解决的。启动以下服务:
    ASP.NET 状态服务
    Remote Procedure Call (RPC)  (默认是已启动不可选)
    Remote Procedure Call (RPC) Locator安装以下补丁:
    windows installer 3.1新建一个拥有administror权限的帐号程序重编译
    重新安装windows服务
    勾上“允许服务与桌面交互”这个选项
    启动服务。最后试了一下,删除新建的帐号和服务后同样能运行,问题应该出在windows installer 3.1这里。
      

  11.   

    取得路由器IP很简单,你在网站上建立一个WebService,调用这个WebService,让着个WebService返回IP地址即可,返回的肯定是你的公网IP地址
      

  12.   

    to: cellblue(cellblue)
    你在网站上建立一个WebService,调用这个WebService,让着个WebService返回IP地址即可
    =========
    我的網站是動態的IP啊﹐WebService只能建立在公司的綱站上﹐直接通過WebService怎么返回自已綱站的IP? 我是通過用在公司的放一個綱頁﹐然后訪問綱頁后﹐由綱頁取得IP﹐并保存,再由WebServies取出。