Skip to content

软件管理

Windows 系统的软件管理包括应用程序的安装、更新、卸载等操作。本章介绍多种软件管理方法。

软件安装概述

安装方式

Windows 系统支持多种软件安装方式:

方式说明特点
应用商店Microsoft Store安全、自动更新
安装程序.exe 安装包最常见的方式
MSI 安装包.msi 文件企业部署常用
绿色软件免安装直接运行
包管理器winget、Chocolatey命令行安装

安装位置

text
# 默认安装位置
C:\Program Files\           # 64位程序
C:\Program Files (x86)\     # 32位程序
C:\ProgramData\             # 共享程序数据
%LOCALAPPDATA%\Programs\    # 用户级程序

# 修改默认安装位置
# 设置 → 系统 → 存储 → 更改新内容的保存位置

Microsoft Store

使用应用商店

Microsoft Store 是 Windows 内置的应用商店:

  1. 点击开始菜单中的"Microsoft Store"
  2. 搜索或浏览应用
  3. 点击"获取"或"安装"
  4. 等待下载完成

应用商店优点

  • 自动更新应用
  • 安全可靠,经过微软审核
  • 跨设备同步
  • 支持退款

常用命令

powershell
# 打开 Microsoft Store
start ms-windows-store:

# 打开应用下载页面
start ms-windows-store://pdp/?ProductId=应用ID

# 更新所有应用
# 在应用商店中点击"库" → "获取更新"

安装程序(.exe)

运行安装程序

  1. 下载安装程序(.exe 文件)
  2. 双击运行安装程序
  3. 按照向导提示完成安装
  4. 选择安装位置和组件
  5. 完成安装

安装选项

安装时通常需要选择:

  • 安装位置:选择程序安装目录
  • 安装组件:选择需要安装的功能
  • 创建快捷方式:桌面或开始菜单快捷方式
  • 关联文件类型:设置默认打开程序
  • 开机启动:是否随系统启动

静默安装

cmd
:: 常见静默安装参数
:: /S 或 /SILENT 或 /VERYSILENT - 静默安装
:: /D=路径 - 指定安装目录

:: 示例:静默安装 7-Zip
7z.exe /S

:: 示例:指定安装目录
setup.exe /S /D=D:\Software\MyApp

MSI 安装包

什么是 MSI

MSI(Microsoft Installer)是 Windows 安装程序格式:

  • 标准化的安装过程
  • 支持企业部署
  • 可通过组策略分发
  • 支持修复和卸载

安装 MSI 程序

cmd
:: 基本安装
msiexec /i "C:\path\to\setup.msi"

:: 静默安装
msiexec /i "C:\path\to\setup.msi" /quiet

:: 指定安装目录
msiexec /i "C:\path\to\setup.msi" INSTALLDIR="D:\MyApp" /quiet

:: 创建日志
msiexec /i "C:\path\to\setup.msi" /L*V "install.log"

:: 卸载程序
msiexec /x "C:\path\to\setup.msi"

:: 通过产品代码卸载
msiexec /x {产品代码}

MSI 安装选项

参数说明
/i安装程序
/x卸载程序
/f修复安装
/quiet静默模式
/passive无人参与模式
/norestart安装后不重启
/forcerestart强制重启

Windows 包管理器(winget)

winget 简介

Windows Package Manager(winget)是微软官方的命令行包管理器:

  • 类似于 Linux 的 apt 或 yum
  • 支持搜索、安装、更新、卸载软件
  • 支持批量安装
  • 自动处理依赖关系

基本命令

powershell
# 查看 winget 版本
winget --version

# 搜索软件
winget search chrome
winget search "Visual Studio Code"

# 查看软件详细信息
winget show "Google Chrome"

# 安装软件
winget install "Google Chrome"
winget install --id Google.Chrome

# 安装特定版本
winget install --id Google.Chrome --version "100.0.4896.60"

# 指定安装位置
winget install --id Google.Chrome --location "D:\Apps\Chrome"

# 静默安装
winget install --id Google.Chrome --silent

# 跳过许可协议
winget install --id Google.Chrome --accept-package-agreements --accept-source-agreements

管理已安装软件

powershell
# 列出已安装的软件
winget list

# 搜索已安装的软件
winget list chrome

# 更新软件
winget upgrade "Google Chrome"

# 更新所有软件
winget upgrade --all

# 查看可更新的软件
winget upgrade

# 卸载软件
winget uninstall "Google Chrome"
winget uninstall --id Google.Chrome

# 导出已安装软件列表
winget export -o software.json

# 从文件批量安装
winget import -i software.json

winget 配置

powershell
# 查看设置
winget settings

# 打开设置文件
winget settings --enable
# 配置文件位置:%LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json

# 常用配置
# {
#     "$schema": "https://aka.ms/winget-settings.schema.json",
#     "source": {
#         "autoUpdateIntervalInMinutes": 5
#     },
#     "visual": {
#         "progressBar": "accent"
#     },
#     "installBehavior": {
#         "preferences": {
#             "scope": "user"
#         }
#     }
# }

Chocolatey

Chocolatey 简介

Chocolatey 是 Windows 上流行的第三方包管理器:

  • 软件仓库丰富
  • 支持企业版功能
  • 社区活跃
  • 与 PowerShell 深度集成

安装 Chocolatey

powershell
# 以管理员身份运行 PowerShell,执行以下命令
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

# 验证安装
choco --version

基本使用

powershell
# 搜索软件
choco search chrome
choco search vscode

# 查看软件信息
choco info googlechrome

# 安装软件
choco install googlechrome
choco install googlechrome -y  # 自动确认

# 安装特定版本
choco install googlechrome --version 100.0.4896.60

# 安装到自定义位置
choco install googlechrome --install-arguments="'/D=D:\Apps\Chrome'"

# 列出已安装的软件
choco list --local-only

# 更新软件
choco upgrade googlechrome

# 更新所有软件
choco upgrade all -y

# 卸载软件
choco uninstall googlechrome

# 卸载并删除配置
choco uninstall googlechrome -x

Chocolatey 高级功能

powershell
# 创建软件包
choco new mypackage

# 打包软件
choco pack

# 推送到仓库
choco push mypackage.1.0.0.nupkg -s https://push.chocolatey.org/

# 查看过期软件
choco outdated

# 固定软件版本(防止更新)
choco pin add -n googlechrome
choco pin remove -n googlechrome

# 缓存管理
choco cache list
choco cache remove

PowerShell 软件管理

查询已安装软件

powershell
# 方法一:通过注册表查询
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | 
    Format-Table -AutoSize

# 方法二:包含 32 位程序
$programs = @()
$programs += Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* -ErrorAction SilentlyContinue
$programs += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* -ErrorAction SilentlyContinue
$programs | Where-Object { $_.DisplayName } | 
    Select-Object DisplayName, DisplayVersion, Publisher | 
    Sort-Object DisplayName

# 方法三:使用 WMI
Get-CimInstance -ClassName Win32_Product | 
    Select-Object Name, Version, Vendor | 
    Sort-Object Name

# 搜索特定软件
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Where-Object { $_.DisplayName -like "*Chrome*" }

卸载程序

powershell
# 通过 WMI 卸载
$app = Get-CimInstance -ClassName Win32_Product | Where-Object { $_.Name -eq "程序名称" }
$app | Invoke-CimMethod -MethodName Uninstall

# 通过注册表获取卸载命令
$app = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Where-Object { $_.DisplayName -eq "程序名称" }
if ($app.UninstallString) {
    cmd /c $app.UninstallString
}

程序和功能

打开程序和功能

powershell
# 方法一:通过控制面板
control appwiz.cpl

# 方法二:通过设置
# 设置 → 应用 → 安装的应用

# 方法三:通过运行
appwiz.cpl

管理功能

在"程序和功能"中可以:

  • 查看已安装的程序列表
  • 卸载程序
  • 修改程序安装
  • 修复程序安装
  • 启用或禁用 Windows 功能

Windows 功能

powershell
# 查看所有 Windows 功能
Get-WindowsOptionalFeature -Online

# 启用 Windows 功能
Enable-WindowsOptionalFeature -Online -FeatureName "TelnetClient"

# 禁用 Windows 功能
Disable-WindowsOptionalFeature -Online -FeatureName "TelnetClient"

# 通过 DISM 命令
dism /online /enable-feature /featurename:TelnetClient
dism /online /disable-feature /featurename:TelnetClient

启动项管理

查看启动项

powershell
# 通过任务管理器
# Ctrl + Shift + Esc → 启动选项卡

# 通过设置
# 设置 → 应用 → 启动

# 通过 PowerShell 查看启动项
Get-CimInstance Win32_StartupCommand | 
    Select-Object Name, Command, Location, User

# 查看注册表启动项
Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run"

# 查看启动文件夹
$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup

管理启动项

powershell
# 禁用启动项(通过注册表)
Remove-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "程序名"

# 添加启动项
Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "MyApp" -Value "C:\Path\To\App.exe"

# 通过 PowerShell 管理启动项
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut("$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\MyApp.lnk")
$shortcut.TargetPath = "C:\Path\To\App.exe"
$shortcut.Save()

默认程序

设置默认程序

powershell
# 打开默认应用设置
start ms-settings:defaultapps

# 通过设置界面
# 设置 → 应用 → 默认应用

文件关联

powershell
# 查看文件关联
assoc .txt
assoc .docx

# 查看程序关联的文件类型
ftype txtfile

# 修改文件关联(需要管理员权限)
assoc .txt=txtfile
ftype txtfile="C:\Windows\notepad.exe" "%1"

# 通过 PowerShell 查看文件关联
cmd /c "assoc .txt"
cmd /c "ftype txtfile"

软件更新

Windows 更新

powershell
# 检查 Windows 更新
# 设置 → Windows 更新 → 检查更新

# 通过 PowerShell 检查更新
Install-Module PSWindowsUpdate -Force
Get-WindowsUpdate
Install-WindowsUpdate

应用程序更新

大多数应用程序有自己的更新机制:

  • 内置更新检查
  • 自动下载更新
  • 提示用户安装更新
powershell
# 使用 winget 更新所有应用
winget upgrade --all

# 使用 Chocolatey 更新所有应用
choco upgrade all -y

小结

本章介绍了 Windows 软件管理的主要内容:

  1. 安装方式:了解不同的软件安装方法
  2. Microsoft Store:使用应用商店安装应用
  3. 安装程序:运行 .exe 和 .msi 安装包
  4. winget:使用微软官方包管理器
  5. Chocolatey:使用第三方包管理器
  6. PowerShell:通过脚本管理软件
  7. 启动项管理:控制开机启动的程序
  8. 默认程序:设置文件关联

建议:

  • 优先使用 winget 或 Chocolatey 管理软件
  • 定期更新系统和应用程序
  • 合理管理启动项,提高系统启动速度
  • 注意软件来源的安全性