diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..d1a2bf554fc7dc3c73def55b1a9d3eb5d95219b7 --- /dev/null +++ b/README.en.md @@ -0,0 +1,59 @@ +# Console Windows Service + +This is a simple Windows service project designed to demonstrate how to create and manage Windows services. The project is written in C# and utilizes the .NET framework to implement service installation, startup, shutdown, and uninstallation. + +## Features + +- **Service Management**: Supports installation, startup, shutdown, and uninstallation of the service. +- **Scheduled Tasks**: The service includes a timer that executes tasks at specified intervals. +- **Message Box Popup**: The service can display message boxes in the active console session. + +## Installation and Uninstallation + +### Install the Service + +1. Open Command Prompt (run as administrator). +2. Navigate to the project's `bin/Release` directory. +3. Run the following command to install the service: + ```sh + installutil MyWindowsService.exe + ``` + +### Uninstall the Service + +1. Open Command Prompt (run as administrator). +2. Navigate to the project's `bin/Release` directory. +3. Run the following command to uninstall the service: + ```sh + installutil /u MyWindowsService.exe + ``` + +## Usage Instructions + +### Start and Stop the Service + +1. Open the Services management tool (accessible by running `services.msc`). +2. Locate the service named `MyWindowsService`. +3. Right-click the service and select "Start" or "Stop" to manage its status. + +### Configure Scheduled Tasks + +The scheduled task within the service can be configured in the `Service1.cs` file. By default, the timer triggers every 60 seconds. + +```csharp +private Timer _popupTimer; +private int _popupInterval = 60000; // 60 seconds +``` + +Modify the value of `_popupInterval` as needed to adjust the task interval. + +## Code Structure + +- **Program.cs**: Contains the service entry point. +- **Service1.cs**: Implements the core service functionality, including scheduled tasks and message box display. +- **ProjectInstaller.cs**: Contains the service installer logic. +- **WindowsApi.cs**: Contains Windows API calls used to display message boxes in the active session. + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3cc403c4941d775abe4f75c830c6a01f3d176a70 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# 控制台 Windows 服务 + +这是一个简单的 Windows 服务项目,旨在演示如何创建和管理 Windows 服务。该项目使用 C# 编写,并利用 .NET 框架来实现服务的安装、启动、停止和卸载。 + +## 特性 + +- **服务管理**:可以安装、启动、停止和卸载服务。 +- **定时任务**:服务包含一个定时器,可以在指定的时间间隔执行任务。 +- **弹出消息框**:服务能够在活动的控制台会话中显示消息框。 + +## 安装和卸载 + +### 安装服务 + +1. 打开命令提示符(以管理员身份运行)。 +2. 导航到项目的 `bin/Release` 目录。 +3. 运行以下命令来安装服务: + ```sh + installutil MyWindowsService.exe + ``` + +### 卸载服务 + +1. 打开命令提示符(以管理员身份运行)。 +2. 导航到项目的 `bin/Release` 目录。 +3. 运行以下命令来卸载服务: + ```sh + installutil /u MyWindowsService.exe + ``` + +## 使用说明 + +### 启动和停止服务 + +1. 打开“服务”管理工具(可以通过运行 `services.msc` 来打开)。 +2. 找到名为 `MyWindowsService` 的服务。 +3. 右键点击服务,选择“启动”或“停止”来管理服务的状态。 + +### 配置定时任务 + +服务中的定时任务可以在 `Service1.cs` 文件中进行配置。默认情况下,定时器每 60 秒触发一次。 + +```csharp +private Timer _popupTimer; +private int _popupInterval = 60000; // 60 seconds +``` + +你可以根据需要修改 `_popupInterval` 的值来调整定时任务的间隔。 + +## 代码结构 + +- **Program.cs**:包含服务的入口点。 +- **Service1.cs**:实现服务的核心功能,包括定时任务和消息框显示。 +- **ProjectInstaller.cs**:包含服务安装程序的逻辑。 +- **WindowsApi.cs**:包含用于在活动会话中显示消息框的 Windows API 调用。 + +## 许可证 + +该项目使用 MIT 许可证,详情请参见 [LICENSE](LICENSE) 文件。 \ No newline at end of file