In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to create the installation and uninstallation of Windows services and services in C #. The article is very detailed and has certain reference value. Interested friends must finish reading it!
Windows services (that is, previous NT services) enable you to create executable applications that run for a long time in their own Windows sessions. These services can be started automatically when the computer starts, can be paused and restarted, and do not display any user interface. This service is ideal for use on the server, or at any time, when you need to run the feature for a long time in order not to affect other users working on the same computer. You can also run the service in a security context different from the specific user account or the default computer account of the logged-in user.
1. Create Windows service using C#: 1. File-> New-> Project: select the Windows service, modify the project name and location, and then click "OK":
2. Right-click on the default generated service Service1 design interface, select "Properties", and open the properties panel.
3. In the open properties panel, modify common properties:
Name: the name of the background code class.
AutoLog: set to true to automatically write events to the event log of Windows, which can be viewed in the event Viewer
CanPansuAndContinue: set to True, indicating that the service can be paused and resumed
4. Add service installer: right-click on the design interface of Service1 and select "add installer"
5. Modify the properties in the generated "ProjectInstaller Design Interface"
5.1 right-click serviceProcessInstaller1, select "Properties", and open the properties panel of serviceProcessInstaller1:
Account: indicates the type of account used to run this service. User is selected by default and changed to LocalSystem with high permissions.
5.2 right-click serviceInstaller1, select Properties, and open the properties panel of serviceInstaller1
ServiceName: the name displayed in the Windows service
Description: description information displayed in the Windows service
StartType: indicates how and when to start this service Manual: start manually Automatic: start automatically
DelayedAutoStart: indicates whether the service starts with a delay. If the default false is changed to True, it indicates that the service starts with a delay.
6. The solution is rebuilt and the Windows service is created.
Second, install and uninstall Windows services. First, use the DOS command line to install: you must run the DOS command line as an administrator, otherwise the installation will fail due to permission problems.
Execute the command "path to the executable file generated by installutil+" under the command line to install
After entering the command, press enter to install:
This interface indicates that the service is installed successfully. View the newly installed services in system Services:
Uninstall the Windows service:
Enter the "installutil / u executable file path" command on the command line, and then enter
C:\ Windows\ Microsoft.NET\ Framework\ v4.0.30319\ InstallUtil / u F:\ exercise\ Windows Service\ WindowsServiceDemo\ WindowsServiceDemo\ bin\ Debug\ WindowsServiceDemo.exe
Refresh in the system service, can not find the MyFirstService service just now.
Method 2: install the service using a batch file (.bat)
1. Create a new txt text file.
2. Edit the newly created text file:
% SystemRoot%\ Microsoft.NET\ Framework\ v4.0.30319\ installutil.exe F:\ exercise\ Windows Service\ WindowsServiceDemo\ WindowsServiceDemo\ bin\ Debug\ WindowsServiceDemo.exepause
3. Save the file file, modify the file name to .bat, and rename the text file: Install.bat.
Uninstall the service using a batch file (.bat)
1. Create a new txt text file.
2. Edit the newly created text file:
% SystemRoot%\ Microsoft.NET\ Framework\ v4.0.30319\ installutil.exe / u F:\ exercise\ Windows Service\ WindowsServiceDemo\ WindowsServiceDemo\ bin\ Debug\ WindowsServiceDemo.exepause
3. Save the file file, modify the file name to .bat, and rename the text file: Uninstall.bat.
Note: batch files are run as administrators.
Method 3: install using external tools that come with vs
1. Run visual studio as an administrator, open the solution, select "tools"-> "external tools" in the menu bar, and open the external tools interface:
2. Click add to add the installer
Title: InstallService
Command: C:\ Windows\ Microsoft.NET\ Framework\ v4.0.30319\ InstallUtil.exe
Parameters: click the "Arrow button" and select the target file name. Note: add the extended file name of the file after selecting the target file name.
Initial directory: click the "Arrow button" to select the target file directory
3. The final InstallService command should be as follows:
4. Click the apply and OK button to save the configuration.
5. Click the tool options in the menu bar to see the newly added "InstallService" command.
6. Click the "InstallService" command to start the installation, and the output interface will display the installation information:
7. At this point, the service has been installed successfully, and the newly installed service can be viewed in the system service interface.
The above is all the contents of the article "how to create Windows Services and Services installation and Uninstall". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.