开发者

how to start windows service on particular time

开发者 https://www.devze.com 2023-03-04 14:30 出处:网络
i want开发者_运维知识库 to start my windows service on every sunday 1.00 A.M. can anyone help me in thisIf it has to run on every sunday 1.00 AM then probably you need a simple program that is run by

i want开发者_运维知识库 to start my windows service on every sunday 1.00 A.M.

can anyone help me in this


If it has to run on every sunday 1.00 AM then probably you need a simple program that is run by task scheduler on 1 AM Sunday.

It would be better if you use a timer that fires say every one hour and check what day and time it is. If it is sunday and 1 AM you can disable the timer and carry on with the work you want to do in the service. After the work is done then you should re-enable the timer.


One way could be to use SC command in a batch file which can be scheduled to run from windows standard scheduler.

For more information, see

SC /?

start and stop parameters in particular.


Since the logic should be done once in a week at a particular time use windows task scheduler for your purpose.

If you do not know how to perform this, Create a sample.vbs file, which calls your asp.net page/web service where you perform the logic. Then create a schedule in windows task scheduler to trigger your sample.vbs file.

Please see the steps to create the .vbs file that calls your asp.net page/web service

1.Open notepad and copy the following code in it and save

   'Declare variables
      Dim objRequest
      Dim URL

    Set objRequest = CreateObject("Microsoft.XMLHTTP")

   'Put together the URL link appending the Variables.
      URL = "http://computerName/VirtualDirectoryName/Logic.aspx"

  'Open the HTTP request and pass the URL to the objRequest object
      objRequest.open "POST", URL , false

  'Send the HTML Request
      objRequest.Send

  'Set the object to nothing
      Set objRequest = Nothing

2.Edit the URL="with your virtual directory path to the asp.net page/web service" and save.

3.change the extension from ".txt" to ".vbs" and save.

4.Create a new schedule in windows "Task Scheduler" and point the newly created sample.vbs file which will call the page where your logic is written (http://computerName/VirtualDirectoryName/Logic.aspx) and edit the settings to run once in a week at a particular time.


The way I do it is like this:

  1. First you install your windows service on your Windows Server.
  2. Second, you make a batch file. You just open Notepad, write the line beneath and save it as a .bat.

    net start myService

  3. Then you use the Task Scheduler available in Windows Server.

Creating the task is easy, you just need to add a trigger event (every sunday) and an action (starting the batch file you've just created).

I'm not saying it is the best way, but it is a way that will work.

0

精彩评论

暂无评论...
验证码 换一张
取 消