Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceProcess;
- using System.Configuration;
- using System.Diagnostics;
- namespace WindowsService
- {
- class WindowsService : ServiceBase
- {
- public WindowsService()
- {
- //Names the Service and gives log file to write/read from
- this.ServiceName = "Windows Service";
- this.EventLog.Log = "Application";
- //Sets the permissions of the service
- this.CanHandlePowerEvent = true;
- this.CanHandleSessionChangeEvent = true;
- this.CanPauseAndContinue = true;
- this.CanShutdown = true;
- this.CanStop = true;
- }
- static void Main()
- {
- ServiceBase.Run(new WindowsService()); //Runs the Service
- }
- #region The differenet functions
- protected override void Dispose(bool disposing) //Disposing
- {
- base.Dispose(disposing);
- }
- protected override void OnStart(string[] args) //On Start up
- {
- base.OnStart(args);
- }
- protected override void OnStop() //On Stop
- {
- base.OnStop();
- }
- protected override void OnPause() //On Pause
- {
- base.OnPause();
- }
- protected override void OnContinue() //On Continue
- {
- base.OnContinue();
- }
- protected override void OnShutdown() //On Shut down
- {
- base.OnShutdown();
- }
- protected override void OnCustomCommand(int command) //On a Custom Command
- {
- base.OnCustomCommand(command);
- }
- protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus) //On a Power event
- {
- return base.OnPowerEvent(powerStatus);
- }
- protected override void OnSessionChange(SessionChangeDescription changeDescription) //On a Session change
- {
- base.OnSessionChange(changeDescription);
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement