当前位置:编程学习 > C#/ASP.NET >>

C#windows服务问题

在vs2010用C# 写了个windows服务,在XP下可以安装运行,但拿到win8下安装的时候就出现了问题,后来查到是windows系统权限的问题,解决之后可以安装了,但安装成功后服务启动之后还是运行不了,不知道问题出在哪里,哪位大神来帮忙看下问题所在?

using System;
using System.ServiceProcess;
using System.Configuration;
using System.IO;

namespace WinServCX
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            string qqpath = ConfigurationSettings.AppSettings["QQ"];
            string alipath = ConfigurationSettings.AppSettings["aliwangwang"];
            string leibaopath = ConfigurationSettings.AppSettings["leibao"];
            string folderpath = ConfigurationSettings.AppSettings["folder"];

            try
            {
                System.Diagnostics.Process.Start(qqpath);
                System.Diagnostics.Process.Start(alipath);
                System.Diagnostics.Process.Start(leibaopath);
                System.Diagnostics.Process.Start(folderpath);
                using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"servrun_log.txt", true))
                {
                    sw.WriteLine(DateTime.Now + " 服务启动成功!" + "\r\n");
                }
            }

            catch(Exception ex)
            {
                using(StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"service_log.txt",true))
                {
                    sw.WriteLine(DateTime.Now + ex.Message + "\r\n");
                }
                this.Dispose();
            }
        }

        protected override void OnStop()
        {
            this.Dispose();
            using (StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"servstop_log.txt", true))
            {
                sw.WriteLine(DateTime.Now + " 服务卸载成功!" + "\r\n");
            }
        }
    }
}

C# Windows 服务 Windows 8 --------------------编程问答-------------------- 你不是有日志输出吗?exMessage 输出什么?
string qqpath = ConfigurationSettings.AppSettings["QQ"];
string alipath = ConfigurationSettings.AppSettings["aliwangwang"];
string leibaopath = ConfigurationSettings.AppSettings["leibao"];
string folderpath = ConfigurationSettings.AppSettings["folder"]; 
都有没有获得正确的路径?
进程中有没有这些程序? --------------------编程问答-------------------- 看Event View 里有什么异常。 --------------------编程问答-------------------- 补充一下,程序打印出来的异常信息日志,显示服务器启动失败,看不懂是啥意思 --------------------编程问答--------------------
引用 1 楼 devmiao 的回复:
你不是有日志输出吗?exMessage 输出什么?
string qqpath = ConfigurationSettings.AppSettings["QQ"];
string alipath = ConfigurationSettings.AppSettings["aliwangwang"];
string leibaopath = ConfigurationSettings.AppSe……


程序打印出来的异常信息日志,显示(服务器启动失败),看不懂是啥意思  --------------------编程问答--------------------
引用 1 楼 devmiao 的回复:
你不是有日志输出吗?exMessage 输出什么?
string qqpath = ConfigurationSettings.AppSettings["QQ"];
string alipath = ConfigurationSettings.AppSettings["aliwangwang"];
string leibaopath = ConfigurationSettings.AppSe……

补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,