# 适用于 Windows 的 Linux 子系统 **Repository Path**: windowsuninstaller/LSW ## Basic Information - **Project Name**: 适用于 Windows 的 Linux 子系统 - **Description**: 在 Linux 系统上无缝运行 Windows 程序 —— WSL 的反向实现(Wine 封装) - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2026-08-23 - **Last Updated**: 2026-09-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: Linux, Cli, Windows, Wine, Bash ## README # LSW - Linux Subsystem for Windows > 在 Linux 系统上无缝运行 Windows 程序 —— WSL 的反向实现(Wine 封装) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://mit-license.org/) [![Platform: Debian/Ubuntu Linux](https://img.shields.io/badge/Platform-Debian/Ubuntu-blue.svg)](#) [![Powered by Wine](https://img.shields.io/badge/Powered%20by-Wine-purple.svg)](#) --- ## 项目简介 LSW(Linux Subsystem for Windows)是一个轻量级的命令行工具,借助 **Wine** 兼容层,让你在 Linux 环境中像在 Windows 上一样运行 `.exe` 程序和 Windows 命令行工具。 如果你熟悉 **WSL**(Windows Subsystem for Linux)—— 在 Windows 上跑 Linux,那么 LSW 恰好相反:**在 Linux 上跑 Windows**。 **典型场景:** - 运行只有 Windows 版本的命令行工具 - 执行 `.bat` / `.cmd` 批处理脚本 - 快速调用 Windows 的 `cmd.exe` 进行交互 - 无需切换系统即可测试跨平台脚本 --- ## 功能特性 | 功能 | 说明 | |------|------| |

🚀 双模式执行

| 支持 `cmd.exe` 交互式 / `--exec` 直接执行两种模式 | |

📂 目录切换

| `--cd` 参数灵活指定 Wine 工作目录,支持 `~` 和绝对路径 | |

🧩 多环境隔离

| `--distribution/-d` 参数支持独立 WINEPREFIX,隔离多个 Windows 环境 | |

🔧 一键管理

| 内置安装、卸载、关机、版本、帮助等管理命令 | |

🤏 小而美

| bash 主脚本仅约 6KB(Wine 依赖需额外占用磁盘) | --- ## 系统要求 - **操作系统**:基于 Debian/Ubuntu 的 Linux 发行版(`apt` 包管理器) - **权限**:具有 `sudo` 权限的普通用户 - **磁盘空间**:至少 500MB(用于 Wine 及其依赖) --- ## 安装指南 ### 一键安装 克隆或下载本项目后,在项目目录下执行: ```bash ./lsw --install ``` 或: ```bash bash install.sh ``` 安装过程会自动完成以下操作: 1. 将 `lsw` 主程序复制到 `/bin/lsw`(全局可用) 2. 将帮助文档安装到 `/etc/LSW.help.UTF-8.txt` 3. 通过 `apt` 自动安装 **Wine** 兼容层 4. 初始化 Wine 配置(`~/.wine` 前缀) ### 我已经提前安装好了wine ```bash bash install_nowine.sh ``` 安装过程会自动完成以下操作: 1. 将 `lsw` 主程序复制到 `/bin/lsw`(全局可用) 2. 将帮助文档安装到 `/etc/LSW.help.UTF-8.txt` ### 我想更新 LSW 命令行程序(本地) 先把仓库clone到本地目录,然后执行更新命令: ```bash ./lsw --offlineupdate ``` ### 我想在线更新 LSW 命令行程序(远程) ```bash ./lsw --update ``` 将会自动从仓库下载最新版本的 LSW 命令行程序,然后执行更新操作。 ### 验证安装 安装完成后,输入以下命令验证: ```bash lsw --version ``` --- ## 使用方法 ### 基本使用 #### 1. 启动交互式 CMD 不带任何参数,直接进入 Windows CMD 交互环境: ```bash lsw ``` 你会看到类似的提示符: ``` Microsoft Windows [版本 10.0.xxx] (c) Microsoft Corporation. All rights reserved. C:\windows\system32>_ ``` 此时可以输入任意 Windows 命令,如 `dir`、`echo`、`ver` 等,输入 `exit` 退出。 #### 2. 单行命令执行 直接在 `lsw` 后跟上要执行的 Windows 命令: ```bash lsw echo Hello, LSW! lsw dir C:\ lsw "echo 你好 && ver" ``` > 💡 **提示**:包含特殊字符(如 `&&`、`|`、`>`)的命令请用引号包裹。 --- ### 执行模式 LSW 提供两种执行模式,按需选用: #### 模式 A:CMD 模式(默认) 所有命令通过 `wine cmd.exe /c` 执行,支持批处理语法: ```bash lsw ver ``` #### 模式 B:Exec 模式(`--exec` / `-e`) 跳过 `cmd.exe`,直接由 Wine 加载可执行文件,性能略优: ```bash # 直接运行 notepad.exe(不需要 cmd.exe 介入) lsw --exec notepad.exe # 简写形式 lsw -e notepad ``` 注:Exec模式不支持 &&、|、> 等CMD批处理语法,适合直接调用独立exe程序。 --- ### 工作目录切换 使用 `--cd <路径>` 参数指定 Wine 的工作目录。 ```bash # 切换到 Linux 用户主目录(~ 会自动展开为 $HOME) lsw --cd ~ dir # 切换到绝对路径 lsw --cd /home/user/Downloads my_program.exe # 与 --exec 组合使用 lsw --cd /tmp --exec ./setup.exe ``` 路径规则: - 以 `/` 开头 → Linux 绝对路径 - 以 `~` 开头 → 用户主目录 - 其他 → 相对当前 shell 路径 --- ### 多环境隔离(WINEPREFIX) 使用 `--distribution <名称>` 或 `-d <名称>` 参数,可以为不同场景创建独立的 Wine 前缀(WINEPREFIX),实现多环境互不干扰。 ```bash # 使用名为 "mywine" 的独立环境(对应 ~/.wine_mywine) lsw -d mywine ver # 长格式写法 lsw --distribution Windows11 notepad.exe # 与 --exec 组合使用 lsw -d testenv --exec setup.exe # 也可以直接传入绝对路径作为 WINEPREFIX lsw -d /opt/wine-custom echo hello ``` 路径规则: - 以 `/` 开头 → 直接作为 WINEPREFIX 绝对路径 - 其他名称 → 自动映射为 `$HOME/.wine_<名称>` > 💡 **提示**:首次使用新的 WINEPREFIX 名称时,Wine 会自动初始化该前缀环境。 --- ### 管理命令 | 命令 | 说明 | |------|------| | `lsw --help` | 显示完整帮助信息 | | `lsw --version` / `-v` | 显示内核版本、Wine 版本、CMD 版本 | | `lsw --install` | 安装 LSW 到系统 | | `lsw --uninstall` | 卸载 LSW(不卸载 Wine) | | `lsw --shutdown` | 退出所有 Wine 进程,关闭 Wine 服务器 | | `lsw --distribution/-d <名称>` | 使用独立的 WINEPREFIX 环境运行 | --- ## 文件结构 ``` WSLForLinuxLSW/ ├── lsw # 主程序脚本(Bash) ├── install.sh # 完整安装脚本(含 Wine 安装) ├── install_nowine.sh # 轻量安装脚本(跳过 Wine 安装) ├── help.UTF-8.txt # 帮助文档(中文版 ├── LICENSE # MIT 开源许可证 ├── .gitignore # Git 忽略文件 └── README.md # 你正在阅读的这份文件 ``` --- ## 常见问题 ### Q1: 安装时提示 `sudo: 找不到命令`? 请确认当前用户具有 sudo 权限,或切换到 root 用户执行安装。 ### Q2: 运行 `lsw` 后显示中文乱码? 确保你的 Linux 终端已启用 UTF-8 编码,并安装了中文字体: ```bash sudo apt install -y fonts-wqy-microhei ``` ### Q3: 如何运行带路径的 EXE 文件? 两种方式均可: ```bash # 使用 Linux 路径 lsw --exec /home/user/app/tool.exe # 在 Wine 中映射为 Windows 盘符后运行 lsw "Z:\home\user\app\tool.exe" ``` ### Q4: Wine 进程卡住了怎么办? 执行关机命令强制退出所有 Wine 进程: ```bash lsw --shutdown ``` ### Q5: 可以同时运行多个 LSW 实例吗? 可以。Wine 服务器会复用现有前缀,多个实例共享同一份 `~/.wine` 配置。 --- ## 卸载 卸载 LSW **不会**删除 Wine 和你的 `~/.wine` 配置,仅移除 LSW 自身: ```bash lsw --uninstall ``` 如需彻底清理 Wine,额外执行: ```bash sudo apt remove --purge -y wine* rm -rf ~/.wine ``` --- ## 致谢 - 本项目基于开源的 [Wine](https://www.winehq.org/) 兼容层 - 灵感来源于 Microsoft 的 **WSL** (Windows Subsystem for Linux) --- 版权所有 (c) Windows卸载程序。使用[MIT开源许可证](LICENSE)。 请勿和 Microsoft 的 **WSL** (Windows Subsystem for Linux) 混淆。