[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 860
  • Last Modified:

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

Hi
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.

Thanks
0
Charles Baldo
Asked:
Charles Baldo
  • 2
3 Solutions
 
jgordosCommented:
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.

http://www.developerdotstar.com/community/node/280

-john
0
 
CoyotesITCommented:
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.

http://www.c-sharpcorner.com/UploadFile/ankithakur/Passing_parameters_to_Windows_Services10062006000204AM/Passing_parameters_to_Windows_Services.aspx


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");


0
 
CoyotesITCommented:
can i ask why you dont just use a scheduled task?
0
 
Charles BaldoSoftware DeveloperAuthor Commented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now