C # create, install, and delete Windows Services

Source: Internet
Author: User
The following is a reference clip:
{
//
// CareEye
//
This. ServiceName = "CareEye ";
}
/**////
/// Clear all resources in use.
///
Protected override void Dispose (bool disposing)
{
If (disposing)
{
If (components! = Null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
/**////
/// Set specific operations so that the service can perform its work.
///
Protected override void OnStart (string [] args)
{
// TODO: Add code here to start the service.
MainThread. Start ();
}
/**////
/// Stop the service.
///
Protected override void OnStop ()
{
// TODO: Add code here to stop the service.
MainThread. Abort ();
}
Public static void ThreadFunc ()
{
Int LastHour = DateTime. Now. Hour;
While (true)
{
System. Threading. Thread. Sleep (60000 );
If (DateTime. Now. Hour-1 = LastHour)
{
MessageBox. Show ("to take good care of your eyes, please take a 5-minute break and look into the distance! "," Warning ", MessageBoxButtons. OK, MessageBoxIcon. Warning, MessageBoxDefaultButton. Button1, MessageBoxOptions. defaulttoptoponly );
LastHour = DateTime. Now. Hour;
}
}
}
}
}

 

 

Add and install components:
On the Design page, right-click and select add installer from the shortcut menu. A new page is displayed, with the following controls: serviceProcessInstaller1 and serviceInstaller1.

Change the attribute Account to LocalSystem in serviceProcessInstaller1.

Change the attribute Parent to serviceProcessInstaller1 in serviceInstaller1. The ServiceName attribute is the name of the service after the service is generated.

After the token is completed, generate the token (fake name is w2.exe ). Find the generated EXE file in the corresponding folder, and find the two. EXE files with short names. Copy the file to the root directory of the drive F in a folder.

Install a service. Go to the cmd screen and enter the Framework2.0 file, for example:

Cd C: \ WINDOWS \ Microsoft. NET \ Frameworkv2.0.50727

After hitting

InstallUtil f: w2.exe. the uninstallation service is InstallUtil f: w2.exe-u.

Now you have to start the service,

Start the installed Service in windows.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.