急:请帮助windows服务从某个文件夹位置压缩文件 [英] urgent: please help windows service to zip file from a certain folder location

查看:66
本文介绍了急:请帮助windows服务从某个文件夹位置压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码的新手。开始创建我的第一个windowsservice来从特定位置压缩文件请查看此代码

zip文件不是在path2的输出文件夹的相应位置创建的。



请在这方面帮助我,并在最后附上日志..

请帮助你们需要帮助



I am new to coding. Started creating my 1st windowsservice to zip files from a certain location please review this code
The zip file is not created in the appropriate location of output folder in path2.

Please help me in this regard also attaching the logs at the end..
Please help need assistance from you guys

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.Timers;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;


namespace WindowsServiceZip
{
    public partial class WindowsServiceZip : ServiceBase
    {
        Timer timer;
        string path1 = @"D:\Zipped_Files\New_Text_Document.txt";
        string path2 = @"D:\output\filezipname.7z";
        string path3 = @"D:\Zipped_Files\R_23122015.txt";


        int timerInterval = 60000;

        public WindowsServiceZip()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Elapsed += new ElapsedEventHandler(this.timer_Elapsed);
            timer.Interval = timerInterval;
            timer.Enabled = true;

        }

        protected override void OnStart(string[] args)
        {
            timer.Start();
        }

        protected override void OnStop()
        {
            timer.Stop();
            timer.SynchronizingObject = null;
            timer.Elapsed -= new ElapsedEventHandler(this.timer_Elapsed);
            timer.Dispose();
            timer = null;


        }
        public void timer_Elapsed(object sender, ElapsedEventArgs e)
        {

            ZipFile z = ZipFile.Create(path2);       //(filezipname);
            z.BeginUpdate();
            z.Add(path1);
            z.Add(path3);
            z.CommitUpdate();
            z.Close();


        }
    }
}





运行与开发人员之后cmd提示并安装在installutil.exe windowsservicezip.exe我得到以下日志文​​件但是没有创建zip



运行事务安装。



开始安装的安装阶段。

请参阅D:\ vs_wpf \ WindowsServiceZip \ WindowsServiceZip \ bin的日志文件内容\Debug\WindowsServiceZip.exe程序集的进度。

该文件位于D:\ _vs_wpf \ WindowsServiceZip \ WindowsServiceZip \bin \Debug \ Windows ServiceZip.InstallLog。



安装阶段已成功完成,提交阶段已开始。

请参阅D:\vs_wpf \日志文件的内容WindowsServiceZip \ WindowsServiceZip \ bin \Debug \ WindowsServiceZip.exe程序集的进度。

文件e位于D:\ _vs_wpf \ WindowsServiceZip \ WindowsServiceZip \\\\Debug \ Windows ServiceZip.InstallLog。



提交阶段已成功完成。< br $>


已完成事务处理安装。



After running vs developer cmd prompt and installing in installutil.exe windowsservicezip.exe i am getting the following log file but zip is not getting created

Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.exe assembly's progress.
The file is located at D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.InstallLog.

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.exe assembly's progress.
The file is located at D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.InstallLog.

The Commit phase completed successfully.

The transacted install has completed.

推荐答案

检查服务是否以管理员权限运行,以便它可以访问此文件夹并在其中写入一个zip。
Check whether the service is running with admin privileges so it can access this folder and write a zip in it.


这篇关于急:请帮助windows服务从某个文件夹位置压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆