Need c# windows service program to execute a batch file at a specific time on winserver 2003

Posted on 2008-11-18
Last Modified: 2013-12-17
If someone has a link to a site that will show me how to write a  c# windows service program to execute a  cmd line .bat batch file at a specific time on windows server 2003?

What I have is a simple .bat file that does a xcopy backup for me. Does the job well. I want to execute it every day at 2am. I was thinking of writing a c# windows service to do it. vb is ok as well. If anyone has a better idea I am interetsed as well.

Question by:charlesbaldo
    LVL 11

    Accepted Solution

    You can use the .net function "shell()"...

    There are some wrapper classes available (freeware) on the net to wrap this all up in a pretty little bow for you.

    LVL 8

    Assisted Solution

    Here is a site with a tutorial on creating a c# service app, along with passing a parameter to it. I would recommend you use a parameter for the time you want this to run the batch file.

    once the service is installed and running with the configured parameter (time of day you want this process to run) then run the file if the current time equals your parameter i.e. 02:00

    using System.Diagnostics.Process.Start("c:\\winnt\\notepad.exe");

    LVL 8

    Assisted Solution

    can i ask why you dont just use a scheduled task?

    Author Closing Comment

    Thanks both,

    In answer to CoyotesIT. Because I didn't think of it Will look into it. Thast some of the exact feed back I was hoping for.   Also I wanted to learn to write a service. This is as much a learning task, hobby task as a business task.

    Thanks to both

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now