├── .gitignore ├── LICENSE ├── README.md ├── alist_icon.ico ├── alist_service_installer.py ├── alist_service_installer.spec ├── nssm.exe └── version_info.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # UV 98 | # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | #uv.lock 102 | 103 | # poetry 104 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 105 | # This is especially recommended for binary packages to ensure reproducibility, and is more 106 | # commonly ignored for libraries. 107 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 108 | #poetry.lock 109 | 110 | # pdm 111 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 112 | #pdm.lock 113 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 114 | # in version control. 115 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 116 | .pdm.toml 117 | .pdm-python 118 | .pdm-build/ 119 | 120 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 121 | __pypackages__/ 122 | 123 | # Celery stuff 124 | celerybeat-schedule 125 | celerybeat.pid 126 | 127 | # SageMath parsed files 128 | *.sage.py 129 | 130 | # Environments 131 | .env 132 | .venv 133 | env/ 134 | venv/ 135 | ENV/ 136 | env.bak/ 137 | venv.bak/ 138 | 139 | # Spyder project settings 140 | .spyderproject 141 | .spyproject 142 | 143 | # Rope project settings 144 | .ropeproject 145 | 146 | # mkdocs documentation 147 | /site 148 | 149 | # mypy 150 | .mypy_cache/ 151 | .dmypy.json 152 | dmypy.json 153 | 154 | # Pyre type checker 155 | .pyre/ 156 | 157 | # pytype static type analyzer 158 | .pytype/ 159 | 160 | # Cython debug symbols 161 | cython_debug/ 162 | 163 | # PyCharm 164 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 165 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 166 | # and can be added to the global gitignore or merged into this file. For a more nuclear 167 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 168 | #.idea/ 169 | 170 | # PyPI configuration file 171 | .pypirc 172 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🌟 Alist Windows 服务安装工具 2 | 3 | Alist Windows 服务安装工具是一个便捷的安装程序,帮助用户在Windows系统上快速安装和配置Alist服务。该工具支持将Alist注册为Windows服务,并提供了简单的卸载和管理方法。 4 | 5 | ## 📖 项目简介 6 | 7 | Alist是一款强大的文件列表程序,支持多种存储服务和云盘,包括但不限于: 8 | - 本地存储 9 | - 阿里云盘 10 | - OneDrive 11 | - Google Drive 12 | - 百度网盘 13 | - 天翼云盘 14 | - 夸克网盘 15 | - S3兼容存储 16 | - WebDAV 17 | - FTP/SFTP 18 | 19 | 通过本安装工具,您可以在Windows系统上一键部署Alist,并将其设置为系统服务,实现开机自启动和后台运行,无需手动管理进程。 20 | 21 | ## 💻 系统要求 22 | 23 | - Windows 7/8/10/11 或 Windows Server 2012/2016/2019/2022 24 | - 管理员权限(安装服务必需) 25 | - 至少100MB可用磁盘空间 26 | - .NET Framework 4.5或更高版本(通常已预装在Windows系统中) 27 | - 开放的5244端口(Alist默认Web端口) 28 | 29 | ## 🛠️ 安装步骤 30 | 31 | 1. **准备文件**: 32 | - 下载`alist_service_installer.exe`安装程序 33 | - 程序会自动包含`alist.exe`和`nssm.exe`,无需单独下载 34 | 35 | 2. **运行安装程序**: 36 | - 右键点击`alist_service_installer.exe` 37 | - 选择"以管理员身份运行" 38 | - 如果出现UAC提示,请点击"是"允许程序运行 39 | 40 | 3. **配置安装选项**: 41 | 安装程序支持以下命令行参数: 42 | ``` 43 | --install-dir "D:\MyAlist" # 自定义安装目录 44 | --service-name "MyAlist" # 自定义服务名称 45 | --port 5244 # 设置Alist监听端口 46 | --force # 强制重新安装 47 | --no-shortcut # 不创建桌面快捷方式 48 | --no-path # 不添加到系统环境变量PATH 49 | --no-confirm # 跳过确认提示直接安装 50 | ``` 51 | 52 | 例如:`alist_service_installer.exe --install-dir "D:\MyAlist" --port 8080` 53 | 54 | 4. **确认安装**: 55 | - 程序会显示安装信息和警告 56 | - 输入"y"确认安装 57 | - 安装过程会自动执行,包括: 58 | * 释放文件到安装目录 59 | * 初始化Alist配置 60 | * 注册Windows服务 61 | * 添加环境变量 62 | * 创建桌面快捷方式 63 | 64 | 5. **完成安装**: 65 | - 安装完成后,程序会显示访问地址和管理员密码 66 | - 请保存好管理员密码,这是访问Alist管理界面的唯一凭证 67 | 68 | ## 🚀 使用说明 69 | 70 | ### 基本访问 71 | - 安装完成后,打开浏览器访问 `http://localhost:5244` 即可使用Alist 72 | - 首次访问管理界面的账号为 `admin`,密码为安装程序显示的随机密码 73 | 74 | ### 服务管理 75 | - **启动服务**:`net start AlistService` 76 | - **停止服务**:`net stop AlistService` 77 | - **重启服务**:`net stop AlistService && net start AlistService` 78 | - **查看服务状态**:`sc query AlistService` 79 | 80 | ### 命令行操作 81 | Alist提供了丰富的命令行功能,常用命令如下: 82 | - **查看管理员信息**:`alist admin info` 83 | - **重置管理员密码**:`alist admin reset` 84 | - **手动启动服务**:`alist server` 85 | - **查看帮助**:`alist --help` 86 | - **查看版本**:`alist version` 87 | - **创建新用户**:`alist admin add [username] [password] [2fa]` 88 | 89 | ### 文件位置 90 | - **可执行文件**:`C:\Program Files\Alist\alist.exe` 91 | - **配置文件**:`C:\Program Files\Alist\data\config.json` 92 | - **数据库文件**:`C:\Program Files\Alist\data\data.db` 93 | - **日志文件**:`C:\Program Files\Alist\data\log\xxx.log` 94 | 95 | ## 🔄 更新Alist 96 | 97 | 要更新Alist到最新版本,您可以: 98 | 99 | 1. 下载最新版本的`alist.exe` 100 | 2. 停止Alist服务:`sc stop AlistService` 101 | 3. 替换安装目录中的`alist.exe` 102 | 4. 启动Alist服务:`sc start AlistService` 103 | 104 | 105 | ## 💻自行编译安装脚本 106 | 107 | 1. 下载最新版本的`alist.exe` 108 | 2. 添加到项目的根目录 109 | 3. 自行使用“PyInstaller” 打包 `pyinstaller --onefile --add-data "alist.exe;." --add-data "nssm.exe;." --uac-admin --icon=alist_icon.ico --versi 110 | on-file=version_info.txt alist_service_installer.py` 111 | 112 | 113 | ## 🗑️ 卸载指南 114 | 115 | 1. 以管理员身份打开命令提示符。 116 | 2. 输入命令:`sc stop AlistService`(停止服务)。 117 | 3. 输入命令:`sc delete AlistService`(删除服务)。 118 | 4. 删除安装目录:`rmdir /s /q "C:\Program Files\Alist"`。 119 | 120 | ## ❓ 常见问题 121 | 122 | - **服务未启动**:请确保以管理员身份运行安装程序,并检查服务状态。 123 | - **无法访问Web界面**:检查防火墙设置,确保端口5244未被阻止。 124 | 125 | ## 🤝 贡献指南 126 | 127 | 欢迎对本项目进行贡献!请通过GitHub提交Pull Request或Issue。 128 | 129 | ## 📬 联系信息 130 | 131 | 如有任何问题或建议,请联系开发者:WKEA 132 | -------------------------------------------------------------------------------- /alist_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wkea/SSRAlist/08b411d7a486d4ea3482639a93fed3219bf323cf/alist_icon.ico -------------------------------------------------------------------------------- /alist_service_installer.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import shutil 4 | import subprocess 5 | import argparse 6 | import ctypes 7 | import tempfile 8 | import traceback 9 | import time 10 | import socket 11 | import winreg 12 | from colorama import init, Fore, Style 13 | 14 | # 初始化colorama以支持彩色输出 15 | init() 16 | 17 | def print_banner(): 18 | """打印程序字符画横幅""" 19 | banner = f""" 20 | {Fore.CYAN} ____ ____ ____ _ _ ___ ____ _____ 21 | / ___|/ ___| | _ \\ / \\ | | |_ _|/ ___||_ _| 22 | \\___ \\\\___ \\ | |_) | / _ \\ | | | | \\___ \\ | | 23 | ___) |___) || _ < / ___ \\ | |___ | | ___) | | | 24 | |____/|____/ |_| \\_\\/_/ \\_\\|_____||___||____/ |_| 25 | 26 | {Fore.YELLOW}---[ALIST安装器]ByWKEA{Style.RESET_ALL} 27 | """ 28 | print(banner) 29 | print(f"{Fore.YELLOW}{'='*70}{Style.RESET_ALL}") 30 | print(f"{Fore.YELLOW}欢迎使用 Alist Windows 服务安装工具{Style.RESET_ALL}") 31 | print(f"{Fore.YELLOW}{'='*70}{Style.RESET_ALL}") 32 | print() 33 | 34 | def print_warning(): 35 | """打印警告信息""" 36 | print(f"\n{Fore.YELLOW}{'='*70}{Style.RESET_ALL}") 37 | print(f"{Fore.RED}【警告】Alist将被注册为Windows系统服务,并设置为开机自启动。{Style.RESET_ALL}") 38 | print(f"{Fore.YELLOW}如需卸载,请按以下步骤操作:{Style.RESET_ALL}") 39 | print(f"1. 以管理员身份打开命令提示符") 40 | print(f"2. 输入命令: {Fore.GREEN}sc stop AlistService{Style.RESET_ALL} (停止服务)") 41 | print(f"3. 输入命令: {Fore.GREEN}sc delete AlistService{Style.RESET_ALL} (删除服务)") 42 | print(f"4. 删除安装目录: {Fore.GREEN}rmdir /s /q \"C:\\Program Files\\Alist\"{Style.RESET_ALL}") 43 | print(f"\n或者使用本工具的{Fore.GREEN}--force{Style.RESET_ALL}参数重新安装来覆盖现有安装") 44 | print(f"{Fore.YELLOW}{'='*70}{Style.RESET_ALL}\n") 45 | 46 | confirm = input(f"{Fore.YELLOW}确认继续安装? (y/n): {Style.RESET_ALL}") 47 | if confirm.lower() != 'y': 48 | print(f"{Fore.RED}安装已取消{Style.RESET_ALL}") 49 | sys.exit(0) 50 | print() 51 | 52 | def is_admin(): 53 | """检查是否具有管理员权限""" 54 | try: 55 | return ctypes.windll.shell32.IsUserAnAdmin() 56 | except: 57 | return False 58 | 59 | def resource_path(relative_path): 60 | """获取资源的绝对路径,适用于PyInstaller打包后的情况""" 61 | try: 62 | base_path = sys._MEIPASS 63 | except Exception: 64 | base_path = os.path.abspath(".") 65 | return os.path.join(base_path, relative_path) 66 | 67 | def get_local_ip(): 68 | """获取本机IP地址""" 69 | try: 70 | # 创建一个临时socket连接以获取本地IP 71 | s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 72 | s.connect(("8.8.8.8", 80)) 73 | ip = s.getsockname()[0] 74 | s.close() 75 | return ip 76 | except: 77 | # 如果失败,尝试其他方法 78 | try: 79 | hostname = socket.gethostname() 80 | ip = socket.gethostbyname(hostname) 81 | return ip 82 | except: 83 | return "localhost" 84 | 85 | def create_desktop_shortcut(url, shortcut_name="Alist文件列表"): 86 | """在桌面创建URL快捷方式""" 87 | try: 88 | # 获取桌面路径 89 | key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 90 | r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") 91 | desktop_path = winreg.QueryValueEx(key, "Desktop")[0] 92 | winreg.CloseKey(key) 93 | 94 | # 创建.url文件 95 | shortcut_path = os.path.join(desktop_path, f"{shortcut_name}.url") 96 | 97 | with open(shortcut_path, "w") as f: 98 | f.write("[InternetShortcut]\n") 99 | f.write(f"URL={url}\n") 100 | f.write("IconIndex=0\n") 101 | # 可以添加图标 102 | # f.write(f"IconFile=C:\\Path\\To\\Icon.ico\n") 103 | 104 | print(f"{Fore.GREEN}已在桌面创建快捷方式: {shortcut_path}{Style.RESET_ALL}") 105 | return True 106 | except Exception as e: 107 | print(f"{Fore.RED}创建桌面快捷方式时出错: {str(e)}{Style.RESET_ALL}") 108 | return False 109 | 110 | def add_to_path(directory): 111 | """将目录添加到系统环境变量PATH中""" 112 | try: 113 | print(f"正在将 {directory} 添加到系统环境变量...") 114 | 115 | # 打开系统环境变量注册表键 116 | env_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 117 | "Environment", 118 | 0, 119 | winreg.KEY_READ | winreg.KEY_WRITE) 120 | 121 | # 获取当前PATH值 122 | try: 123 | path_value, _ = winreg.QueryValueEx(env_key, "PATH") 124 | except: 125 | path_value = "" 126 | 127 | # 检查目录是否已在PATH中 128 | path_dirs = [dir.lower() for dir in path_value.split(';') if dir] 129 | if directory.lower() not in path_dirs: 130 | # 添加目录到PATH 131 | new_path = f"{path_value};{directory}" if path_value else directory 132 | winreg.SetValueEx(env_key, "PATH", 0, winreg.REG_EXPAND_SZ, new_path) 133 | winreg.CloseKey(env_key) 134 | 135 | # 广播环境变量更改消息 136 | HWND_BROADCAST = 0xFFFF 137 | WM_SETTINGCHANGE = 0x001A 138 | SMTO_ABORTIFHUNG = 0x0002 139 | result = ctypes.windll.user32.SendMessageTimeoutW( 140 | HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", 141 | SMTO_ABORTIFHUNG, 5000, ctypes.byref(ctypes.c_ulong())) 142 | 143 | if result == 0: 144 | print(f"{Fore.YELLOW}环境变量已更新,但可能需要重启命令提示符或计算机才能生效{Style.RESET_ALL}") 145 | else: 146 | print(f"{Fore.GREEN}环境变量已成功更新{Style.RESET_ALL}") 147 | 148 | return True 149 | else: 150 | winreg.CloseKey(env_key) 151 | print(f"{Fore.YELLOW}目录 {directory} 已经在PATH环境变量中{Style.RESET_ALL}") 152 | return True 153 | except Exception as e: 154 | print(f"{Fore.RED}添加到环境变量时出错: {str(e)}{Style.RESET_ALL}") 155 | traceback.print_exc() 156 | return False 157 | 158 | def check_existing_installation(install_dir, service_name, nssm_path=None): 159 | """检查是否已存在安装及服务""" 160 | alist_exists = os.path.exists(os.path.join(install_dir, "alist.exe")) 161 | 162 | # 检查服务是否存在 163 | service_exists = False 164 | try: 165 | result = subprocess.run(["sc", "query", service_name], 166 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 167 | service_exists = result.returncode == 0 168 | except: 169 | # 如果sc命令失败,尝试使用nssm检查 170 | if nssm_path and os.path.exists(nssm_path): 171 | try: 172 | result = subprocess.run([nssm_path, "status", service_name], 173 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 174 | service_exists = "SERVICE_" in result.stdout.decode('gbk', errors='ignore') 175 | except: 176 | pass 177 | 178 | return alist_exists, service_exists 179 | 180 | def remove_existing_installation(install_dir, service_name, nssm_path=None): 181 | """移除已存在的安装及服务""" 182 | success = True 183 | 184 | # 尝试使用系统SC命令停止并删除服务 185 | try: 186 | print(f"{Fore.YELLOW}尝试使用SC命令停止并删除服务 '{service_name}'...{Style.RESET_ALL}") 187 | subprocess.run(["sc", "stop", service_name], 188 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 189 | time.sleep(2) 190 | subprocess.run(["sc", "delete", service_name], 191 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 192 | time.sleep(1) 193 | except Exception as e: 194 | print(f"{Fore.RED}使用SC命令移除服务时出错: {str(e)}{Style.RESET_ALL}") 195 | 196 | # 如果服务存在且有nssm路径,再尝试使用nssm停止并移除服务 197 | if nssm_path and os.path.exists(nssm_path): 198 | try: 199 | print(f"{Fore.YELLOW}尝试使用NSSM停止并移除现有服务 '{service_name}'...{Style.RESET_ALL}") 200 | # 停止服务 201 | subprocess.run([nssm_path, "stop", service_name], 202 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 203 | time.sleep(1) 204 | # 移除服务 205 | subprocess.run([nssm_path, "remove", service_name, "confirm"], 206 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 207 | # 等待一会儿确保服务已移除 208 | time.sleep(2) 209 | except Exception as e: 210 | print(f"{Fore.RED}使用NSSM移除服务时出错: {str(e)}{Style.RESET_ALL}") 211 | success = False 212 | 213 | # 确认服务是否已删除 214 | try: 215 | check_result = subprocess.run(["sc", "query", service_name], 216 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 217 | if check_result.returncode == 0: 218 | print(f"{Fore.RED}警告: 服务 '{service_name}' 可能未完全删除{Style.RESET_ALL}") 219 | except: 220 | pass 221 | 222 | # 移除文件 223 | try: 224 | if os.path.exists(os.path.join(install_dir, "alist.exe")): 225 | print(f"{Fore.YELLOW}正在删除现有的 alist.exe...{Style.RESET_ALL}") 226 | os.remove(os.path.join(install_dir, "alist.exe")) 227 | 228 | if os.path.exists(os.path.join(install_dir, "nssm.exe")): 229 | print(f"{Fore.YELLOW}正在删除现有的 nssm.exe...{Style.RESET_ALL}") 230 | os.remove(os.path.join(install_dir, "nssm.exe")) 231 | except Exception as e: 232 | print(f"{Fore.RED}删除文件时出错: {str(e)}{Style.RESET_ALL}") 233 | success = False 234 | 235 | return success 236 | 237 | def extract_files(install_dir): 238 | """提取alist.exe和nssm.exe到安装目录""" 239 | try: 240 | # 创建安装目录(如果不存在) 241 | os.makedirs(install_dir, exist_ok=True) 242 | 243 | # 复制alist.exe到安装目录 244 | alist_src = resource_path("alist.exe") 245 | alist_dst = os.path.join(install_dir, "alist.exe") 246 | shutil.copy2(alist_src, alist_dst) 247 | print(f"{Fore.GREEN}已复制 alist.exe 到 {alist_dst}{Style.RESET_ALL}") 248 | 249 | # 复制nssm.exe到安装目录 250 | nssm_src = resource_path("nssm.exe") 251 | nssm_dst = os.path.join(install_dir, "nssm.exe") 252 | shutil.copy2(nssm_src, nssm_dst) 253 | print(f"{Fore.GREEN}已复制 nssm.exe 到 {nssm_dst}{Style.RESET_ALL}") 254 | 255 | return alist_dst, nssm_dst 256 | except Exception as e: 257 | print(f"{Fore.RED}提取文件时出错: {str(e)}{Style.RESET_ALL}") 258 | traceback.print_exc() 259 | return None, None 260 | 261 | def initialize_alist(alist_path, install_dir): 262 | """初始化Alist(生成配置文件)""" 263 | try: 264 | print(f"{Fore.YELLOW}正在初始化Alist...{Style.RESET_ALL}") 265 | # 切换到安装目录 266 | os.chdir(install_dir) 267 | 268 | # 运行alist命令以初始化 269 | init_process = subprocess.Popen([alist_path, "admin", "random"], 270 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 271 | 272 | # 捕获输出以获取密码 273 | password = None 274 | try: 275 | for line in init_process.stdout: 276 | line_str = line.decode('utf-8', errors='ignore') 277 | if "password" in line_str.lower(): 278 | password = line_str.strip() 279 | print(f"{Fore.GREEN}{line_str.strip()}{Style.RESET_ALL}") 280 | else: 281 | print(line_str.strip()) 282 | except: 283 | pass 284 | 285 | # 等待一段时间让配置文件生成 286 | time.sleep(3) 287 | init_process.terminate() # 终止进程 288 | 289 | print(f"{Fore.GREEN}Alist初始化完成{Style.RESET_ALL}") 290 | return True, password 291 | except Exception as e: 292 | print(f"{Fore.RED}初始化Alist时出错: {str(e)}{Style.RESET_ALL}") 293 | traceback.print_exc() 294 | return False, None 295 | 296 | def install_service(alist_path, nssm_path, install_dir, service_name="AlistService"): 297 | """使用nssm安装alist作为系统服务""" 298 | try: 299 | # 确保服务不存在 300 | try: 301 | subprocess.run(["sc", "stop", service_name], 302 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 303 | subprocess.run(["sc", "delete", service_name], 304 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 305 | except: 306 | pass 307 | 308 | # 再次使用nssm确保服务不存在 309 | subprocess.run([nssm_path, "stop", service_name], 310 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 311 | subprocess.run([nssm_path, "remove", service_name, "confirm"], 312 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 313 | 314 | time.sleep(1) 315 | 316 | # 安装新服务 317 | print(f"{Fore.YELLOW}正在安装服务 '{service_name}'...{Style.RESET_ALL}") 318 | cmd_install = [nssm_path, "install", service_name, alist_path, "server"] 319 | result = subprocess.run(cmd_install, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 320 | 321 | if result.returncode != 0: 322 | error_msg = result.stderr.decode('gbk', errors='ignore') 323 | print(f"{Fore.RED}安装服务失败: {error_msg}{Style.RESET_ALL}") 324 | return False 325 | 326 | # 设置服务描述 327 | subprocess.run([nssm_path, "set", service_name, "Description", "Alist文件列表服务"]) 328 | 329 | # 设置服务工作目录 330 | subprocess.run([nssm_path, "set", service_name, "AppDirectory", install_dir]) 331 | 332 | # 设置服务失败后自动重启 333 | subprocess.run([nssm_path, "set", service_name, "AppExit", "Default", "Restart"]) 334 | 335 | # 设置服务启动参数 336 | subprocess.run([nssm_path, "set", service_name, "AppParameters", "server"]) 337 | 338 | # 设置超时时间 339 | subprocess.run([nssm_path, "set", service_name, "AppStopMethodConsole", "1800000"]) 340 | 341 | # 明确设置服务以LocalSystem账户运行(具有最高权限) 342 | print(f"{Fore.YELLOW}正在设置服务权限为系统账户...{Style.RESET_ALL}") 343 | subprocess.run([nssm_path, "set", service_name, "ObjectName", "LocalSystem"]) 344 | 345 | # 设置服务的启动类型为自动 346 | subprocess.run([nssm_path, "set", service_name, "Start", "SERVICE_AUTO_START"]) 347 | 348 | # 给予服务显示桌面交互的权限 349 | subprocess.run([nssm_path, "set", service_name, "Type", "SERVICE_INTERACTIVE_PROCESS"]) 350 | 351 | print(f"{Fore.YELLOW}服务'{service_name}'安装成功,正在启动...{Style.RESET_ALL}") 352 | 353 | # 赋予安装目录完全权限 354 | try: 355 | print(f"{Fore.YELLOW}正在设置目录权限...{Style.RESET_ALL}") 356 | subprocess.run(["icacls", install_dir, "/grant", "Administrators:(OI)(CI)F", "/T"], 357 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 358 | subprocess.run(["icacls", install_dir, "/grant", "SYSTEM:(OI)(CI)F", "/T"], 359 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 360 | except Exception as e: 361 | print(f"{Fore.YELLOW}设置目录权限时出错: {str(e)}{Style.RESET_ALL}") 362 | 363 | # 启动服务 364 | start_result = subprocess.run([nssm_path, "start", service_name], 365 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 366 | 367 | # 等待服务启动 368 | for i in range(5): 369 | print(f"{Fore.YELLOW}等待服务启动中... ({i+1}/5){Style.RESET_ALL}") 370 | time.sleep(1) 371 | 372 | # 使用SC命令检查服务状态 373 | service_running = False 374 | try: 375 | sc_result = subprocess.run(["sc", "query", service_name], 376 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 377 | sc_output = sc_result.stdout.decode('gbk', errors='ignore') 378 | service_running = "RUNNING" in sc_output 379 | if service_running: 380 | print(f"{Fore.GREEN}服务状态检查: 运行中{Style.RESET_ALL}") 381 | except: 382 | pass 383 | 384 | # 使用NSSM检查服务状态(备用方法) 385 | if not service_running: 386 | try: 387 | status_result = subprocess.run([nssm_path, "status", service_name], 388 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 389 | status_output = status_result.stdout.decode('gbk', errors='ignore') 390 | # 移除所有空格后检查 391 | clean_output = status_output.replace(" ", "") 392 | service_running = "SERVICE_RUNNING" in clean_output or "RUNNING" in clean_output 393 | if service_running: 394 | print(f"{Fore.GREEN}服务状态检查(NSSM): 运行中{Style.RESET_ALL}") 395 | except: 396 | pass 397 | 398 | if service_running: 399 | print(f"{Fore.GREEN}Alist服务 '{service_name}' 已成功运行{Style.RESET_ALL}") 400 | return True 401 | else: 402 | if start_result.returncode != 0: 403 | error_msg = start_result.stderr.decode('gbk', errors='ignore') 404 | print(f"{Fore.RED}启动服务失败: {error_msg}{Style.RESET_ALL}") 405 | else: 406 | # 尝试用不同的命令再次启动服务 407 | try: 408 | print(f"{Fore.YELLOW}尝试使用NET START命令启动服务...{Style.RESET_ALL}") 409 | subprocess.run(["net", "start", service_name], 410 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 411 | time.sleep(2) 412 | # 再次检查状态 413 | sc_result = subprocess.run(["sc", "query", service_name], 414 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) 415 | sc_output = sc_result.stdout.decode('gbk', errors='ignore') 416 | if "RUNNING" in sc_output: 417 | print(f"{Fore.GREEN}使用net start成功启动Alist服务{Style.RESET_ALL}") 418 | return True 419 | except: 420 | pass 421 | 422 | print(f"{Fore.YELLOW}服务安装成功但状态检查失败,可能仍在启动中{Style.RESET_ALL}") 423 | 424 | # 即使状态检查失败,但如果服务已安装,也认为基本成功 425 | return True 426 | except Exception as e: 427 | print(f"{Fore.RED}安装服务时出错: {str(e)}{Style.RESET_ALL}") 428 | traceback.print_exc() 429 | return False 430 | 431 | def get_admin_password(install_dir, init_password=None): 432 | """尝试从data/config.json获取管理员密码""" 433 | if init_password: 434 | return init_password 435 | 436 | try: 437 | import json 438 | config_path = os.path.join(install_dir, "data", "config.json") 439 | if os.path.exists(config_path): 440 | with open(config_path, 'r', encoding='utf-8') as f: 441 | config = json.load(f) 442 | if "password" in config: 443 | return config.get("password") 444 | except Exception as e: 445 | print(f"{Fore.RED}读取配置文件时出错: {str(e)}{Style.RESET_ALL}") 446 | 447 | # 尝试从运行alist admin info命令获取 448 | try: 449 | alist_path = os.path.join(install_dir, "alist.exe") 450 | if os.path.exists(alist_path): 451 | print(f"{Fore.YELLOW}尝试从命令行获取管理员密码...{Style.RESET_ALL}") 452 | info_process = subprocess.Popen([alist_path, "admin", "info"], 453 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, 454 | cwd=install_dir) 455 | for line in info_process.stdout: 456 | line_str = line.decode('utf-8', errors='ignore') 457 | if "password" in line_str.lower(): 458 | info_process.terminate() 459 | return line_str.strip() 460 | info_process.terminate() 461 | except: 462 | pass 463 | 464 | return f"{Fore.YELLOW}未能获取,请查看安装目录下的data/config.json文件或运行'alist.exe admin info'命令获取{Style.RESET_ALL}" 465 | 466 | def main(): 467 | parser = argparse.ArgumentParser(description="Alist Windows服务安装工具") 468 | parser.add_argument("--install-dir", type=str, default="C:\\Program Files\\Alist", 469 | help="Alist安装目录(默认: C:\\Program Files\\Alist)") 470 | parser.add_argument("--service-name", type=str, default="AlistService", 471 | help="Windows服务名称(默认: AlistService)") 472 | parser.add_argument("--force", action="store_true", 473 | help="强制重新安装,即使已存在") 474 | parser.add_argument("--no-shortcut", action="store_true", 475 | help="不创建桌面快捷方式") 476 | parser.add_argument("--no-path", action="store_true", 477 | help="不添加到系统环境变量PATH") 478 | parser.add_argument("--port", type=int, default=5244, 479 | help="Alist服务端口(默认: 5244)") 480 | parser.add_argument("--no-confirm", action="store_true", 481 | help="跳过确认提示直接安装") 482 | 483 | args = parser.parse_args() 484 | 485 | # 打印横幅 486 | print_banner() 487 | 488 | # 检查管理员权限 489 | if not is_admin(): 490 | print(f"{Fore.RED}需要管理员权限来安装系统服务。请以管理员身份运行此程序。{Style.RESET_ALL}") 491 | input("按任意键退出...") 492 | sys.exit(1) 493 | 494 | # 显示警告,除非使用了--no-confirm参数 495 | if not args.no_confirm: 496 | print_warning() 497 | 498 | # 检查是否已安装 499 | print(f"{Fore.CYAN}检查现有安装...{Style.RESET_ALL}") 500 | alist_exists, service_exists = check_existing_installation(args.install_dir, args.service_name) 501 | 502 | # 如果已存在或强制重新安装 503 | if alist_exists or service_exists or args.force: 504 | if args.force: 505 | print(f"{Fore.YELLOW}已指定强制重新安装,正在清理现有安装...{Style.RESET_ALL}") 506 | else: 507 | print(f"{Fore.YELLOW}发现现有安装,正在清理...{Style.RESET_ALL}") 508 | 509 | # 临时提取nssm.exe用于服务清理 510 | temp_dir = tempfile.mkdtemp() 511 | nssm_src = resource_path("nssm.exe") 512 | temp_nssm = os.path.join(temp_dir, "nssm.exe") 513 | shutil.copy2(nssm_src, temp_nssm) 514 | 515 | remove_existing_installation(args.install_dir, args.service_name, temp_nssm) 516 | 517 | # 清理临时文件 518 | try: 519 | os.remove(temp_nssm) 520 | os.rmdir(temp_dir) 521 | except: 522 | pass 523 | 524 | print(f"{Fore.CYAN}开始安装Alist到 {args.install_dir}...{Style.RESET_ALL}") 525 | 526 | # 提取文件 527 | alist_path, nssm_path = extract_files(args.install_dir) 528 | if not alist_path or not nssm_path: 529 | print(f"{Fore.RED}提取文件失败,安装终止。{Style.RESET_ALL}") 530 | input("按任意键退出...") 531 | sys.exit(1) 532 | 533 | # 初始化Alist 534 | init_success, init_password = initialize_alist(alist_path, args.install_dir) 535 | 536 | # 安装服务 537 | success = install_service(alist_path, nssm_path, args.install_dir, args.service_name) 538 | 539 | # 添加到环境变量PATH 540 | path_added = False 541 | if not args.no_path: 542 | path_added = add_to_path(args.install_dir) 543 | 544 | admin_password = get_admin_password(args.install_dir, init_password) 545 | 546 | # 获取IP地址 547 | local_ip = get_local_ip() 548 | alist_url = f"http://{local_ip}:{args.port}" 549 | localhost_url = f"http://localhost:{args.port}" 550 | 551 | if success: 552 | print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}") 553 | print(f"{Fore.GREEN}Alist已成功安装为Windows服务!{Style.RESET_ALL}") 554 | print(f"{Fore.CYAN}{'='*50}{Style.RESET_ALL}") 555 | print(f"- 安装目录: {Fore.YELLOW}{args.install_dir}{Style.RESET_ALL}") 556 | print(f"- 服务名称: {Fore.YELLOW}{args.service_name}{Style.RESET_ALL}") 557 | print(f"- 本机访问地址: {Fore.GREEN}{localhost_url}{Style.RESET_ALL}") 558 | print(f"- 局域网访问地址: {Fore.GREEN}{alist_url}{Style.RESET_ALL}") 559 | print(f"- 默认管理员账号: {Fore.YELLOW}admin{Style.RESET_ALL}") 560 | print(f"- 默认管理员密码: {Fore.GREEN}{admin_password}{Style.RESET_ALL}") 561 | 562 | if path_added: 563 | print(f"- {Fore.CYAN}Alist已添加到系统环境变量,您可以在命令行中直接使用alist命令{Style.RESET_ALL}") 564 | print(f" {Fore.YELLOW}注意:可能需要重新打开命令提示符才能生效{Style.RESET_ALL}") 565 | 566 | print(f"{Fore.CYAN}{'='*50}{Style.RESET_ALL}") 567 | 568 | # 创建桌面快捷方式 569 | if not args.no_shortcut: 570 | create_desktop_shortcut(localhost_url, "Alist文件列表") 571 | 572 | print(f"\n{Fore.YELLOW}提示: 如果服务未自动启动,您可以在命令提示符中运行以下命令手动启动:{Style.RESET_ALL}") 573 | print(f"{Fore.GREEN}net start {args.service_name}{Style.RESET_ALL}") 574 | 575 | print(f"\n{Fore.CYAN}卸载指南:{Style.RESET_ALL}") 576 | print(f"1. 以管理员身份打开命令提示符") 577 | print(f"2. 输入命令: {Fore.GREEN}sc stop {args.service_name}{Style.RESET_ALL}") 578 | print(f"3. 输入命令: {Fore.GREEN}sc delete {args.service_name}{Style.RESET_ALL}") 579 | print(f"4. 删除安装目录: {Fore.GREEN}rmdir /s /q \"{args.install_dir}\"{Style.RESET_ALL}") 580 | 581 | print(f"\n{Fore.CYAN}{'='*50}{Style.RESET_ALL}") 582 | print(f"{Fore.CYAN}Alist常用命令:{Style.RESET_ALL}") 583 | print(f"- 查看管理员信息: {Fore.GREEN}alist admin info{Style.RESET_ALL}") 584 | print(f"- 重置管理员密码: {Fore.GREEN}alist admin random --data \"C:\Program Files\Alist\data\"{Style.RESET_ALL}") 585 | print(f"- 手动启动服务: {Fore.GREEN}alist server{Style.RESET_ALL}") 586 | print(f"- 手动修改密码: {Fore.GREEN}alist admin set YOUR_NEW_PASSWORD --data \"C:\Program Files\Alist\data\"{Style.RESET_ALL}") 587 | print(f"\n{Fore.YELLOW}如果遇到:“token is invalidated”相关错误,请尝试在 后面添加参数 【--data \"C:\Program Files\Alist\data\"】{Style.RESET_ALL}") 588 | print(f"- 查看帮助: {Fore.GREEN}alist --help{Style.RESET_ALL}") 589 | print(f"{Fore.CYAN}{'='*50}{Style.RESET_ALL}") 590 | else: 591 | print(f"{Fore.RED}Alist服务安装过程中遇到问题,但文件已经复制到安装目录。{Style.RESET_ALL}") 592 | print(f"您可以尝试手动运行以下命令启动服务:") 593 | print(f"{Fore.GREEN}cd /d {args.install_dir}{Style.RESET_ALL}") 594 | print(f"{Fore.GREEN}{os.path.join(args.install_dir, 'alist.exe')} server{Style.RESET_ALL}") 595 | 596 | input(f"\n{Fore.YELLOW}按任意键退出...{Style.RESET_ALL}") 597 | 598 | if __name__ == "__main__": 599 | main() 600 | -------------------------------------------------------------------------------- /alist_service_installer.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python ; coding: utf-8 -*- 2 | 3 | 4 | a = Analysis( 5 | ['alist_service_installer.py'], 6 | pathex=[], 7 | binaries=[], 8 | datas=[('alist.exe', '.'), ('nssm.exe', '.')], 9 | hiddenimports=[], 10 | hookspath=[], 11 | hooksconfig={}, 12 | runtime_hooks=[], 13 | excludes=[], 14 | noarchive=False, 15 | optimize=0, 16 | ) 17 | pyz = PYZ(a.pure) 18 | 19 | exe = EXE( 20 | pyz, 21 | a.scripts, 22 | a.binaries, 23 | a.datas, 24 | [], 25 | name='alist_service_installer', 26 | debug=False, 27 | bootloader_ignore_signals=False, 28 | strip=False, 29 | upx=True, 30 | upx_exclude=[], 31 | runtime_tmpdir=None, 32 | console=True, 33 | disable_windowed_traceback=False, 34 | argv_emulation=False, 35 | target_arch=None, 36 | codesign_identity=None, 37 | entitlements_file=None, 38 | version='version_info.txt', 39 | uac_admin=True, 40 | icon=['alist_icon.ico'], 41 | ) 42 | -------------------------------------------------------------------------------- /nssm.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wkea/SSRAlist/08b411d7a486d4ea3482639a93fed3219bf323cf/nssm.exe -------------------------------------------------------------------------------- /version_info.txt: -------------------------------------------------------------------------------- 1 | # UTF-8 2 | # 3 | # For more details about fixed file info 'ffi' see: 4 | # http://msdn.microsoft.com/en-us/library/ms646997.aspx 5 | VSVersionInfo( 6 | ffi=FixedFileInfo( 7 | # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) 8 | # Set not needed items to zero 0. 9 | filevers=(1, 0, 0, 0), 10 | prodvers=(1, 0, 0, 0), 11 | # Contains a bitmask that specifies the valid bits 'flags'r 12 | mask=0x3f, 13 | # Contains a bitmask that specifies the Boolean attributes of the file. 14 | flags=0x0, 15 | # The operating system for which this file was designed. 16 | # 0x4 - NT and there is no need to change it. 17 | OS=0x40004, 18 | # The general type of file. 19 | # 0x1 - the file is an application. 20 | fileType=0x1, 21 | # The function of the file. 22 | # 0x0 - the function is not defined for this fileType 23 | subtype=0x0, 24 | # Creation date and time stamp. 25 | date=(0, 0) 26 | ), 27 | kids=[ 28 | StringFileInfo( 29 | [ 30 | StringTable( 31 | u'080404b0', 32 | [StringStruct(u'CompanyName', u'WKEA'), 33 | StringStruct(u'FileDescription', u'Alist Windows服务安装工具'), 34 | StringStruct(u'FileVersion', u'1.0.0.0'), 35 | StringStruct(u'InternalName', u'alist_installer'), 36 | StringStruct(u'LegalCopyright', u'Copyright (c) 2025 WKEA'), 37 | StringStruct(u'OriginalFilename', u'alist_service_installer.exe'), 38 | StringStruct(u'ProductName', u'Alist安装器'), 39 | StringStruct(u'ProductVersion', u'1.0.0.0')]) 40 | ]), 41 | VarFileInfo([VarStruct(u'Translation', [2052, 1200])]) 42 | ] 43 | ) --------------------------------------------------------------------------------