Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion website/docs/doc/GeneralUpdate.Bowl.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,4 @@ MyApp/

- [Bowl 示例代码](https://github.com/GeneralLibrary/GeneralUpdate-Samples/tree/main/src/Bowl)
- [GeneralUpdate 仓库](https://github.com/GeneralLibrary/GeneralUpdate)
- [Dump 指南](../guide/Dump)
- [Dump 指南](../guide/Deployment and Operations)
2 changes: 1 addition & 1 deletion website/docs/doc/GeneralUpdate.Differential.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,4 @@ await new GeneralUpdateBootstrap()
- [GeneralUpdate 仓库](https://github.com/GeneralLibrary/GeneralUpdate)
- [Samples 差分示例](https://github.com/GeneralLibrary/GeneralUpdate-Samples/tree/main/src/Hub/Samples/DifferentialSample.cs)
- [Core DiffPipeline 文档](GeneralUpdate.Core)
- [Tools 打包指南](../guide/Packaging)
- [Tools 打包指南](../guide/Deployment and Operations)
2 changes: 1 addition & 1 deletion website/docs/doc/GeneralUpdate.Extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,4 @@ report-extension_1.0.0.zip

- [扩展管理示例](https://github.com/GeneralLibrary/GeneralUpdate-Samples/tree/main/src/Hub/Samples/ExtensionSample.cs)
- [GeneralUpdate 仓库](https://github.com/GeneralLibrary/GeneralUpdate)
- [打包指南](../guide/Packaging)
- [打包指南](../guide/Deployment and Operations)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
sidebar_position: 6
sidebar_position: 1
---

# 打包与部署
# 部署与运维指南

本文档介绍如何将应用程序与其更新系统打包,分发给最终用户
本文档涵盖应用程序打包部署、平台适配、故障排查和运维诊断

---

Expand Down Expand Up @@ -120,7 +120,7 @@ await new GeneralUpdateBootstrap()
**避免 C 盘权限问题:**

- 建议默认安装到 `%LOCALAPPDATA%` 而非 `C:\Program Files\`
- 如必须安装在 C 盘,参考 [权限指南](./Permission) 配置注册表降权
- 如必须安装在 C 盘,参考下方 [Windows 权限处理](#五windows-权限处理) 章节

**Windows 发布命令:**

Expand Down Expand Up @@ -238,7 +238,167 @@ jobs:

---

## 五、版本号管理
## 五、Windows 权限处理

### UAC 与安装目录

![](imgs\UAC.png)

使用 GeneralUpdate 进行自动更新时,如果更新目录位于 C 盘,尤其在替换文件或应用补丁时可能会遇到权限问题。Windows 11 对 C 盘某些目录的权限管理比以往更加严格。

以下目录可能触发权限问题:

| 名称 | 目录 |
| --- | --- |
| 系统文件夹 | C:\Windows |
| 注册表配置 | C:\Windows\System32\config |
| 驱动文件夹 | C:\Windows\System32\drivers |
| 程序文件夹 | C:\Program Files 和 C:\Program Files (x86) |

推荐的避免权限问题的目录:

| 名称 | 目录 |
| --- | --- |
| 用户数据目录 | AppData |
| 系统临时目录 | Temp |

### 降低 UAC 级别

> **警告:** 以下方法不建议在生产环境中使用,可能对用户造成安全风险。

如果在更新过程中遇到 UAC 弹窗或权限拒绝问题,可考虑通过修改注册表降低 UAC 控制级别:

| 注册表项 | 新值 | 默认值 |
| --- | --- | --- |
| enableLUA | 0 | 1 |
| ConsentPromptBehaviorAdmin | 0 | 5 |

更新前修改以上注册表(重启电脑后生效),更新完成后务必恢复原值。

**C# 修改注册表:**

```csharp
using Microsoft.Win32;

public void UpdateRegistry()
{
const string keyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";

using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName, true))
{
if (key != null)
{
key.SetValue("EnableLUA", 0, RegistryValueKind.DWord);
key.SetValue("ConsentPromptBehaviorAdmin", 0, RegistryValueKind.DWord);
}
}
}
```

**批处理脚本修改注册表:**

```bat
@echo off
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f
```

**参考链接:**
- [User Account Control 工作原理](https://learn.microsoft.com/zh-cn/windows/security/application-security/application-control/user-account-control/how-it-works)
- [Windows 用户账户控制](https://blog.walterlv.com/post/windows-user-account-control.html)

---

## 六、文件占用排查

### Windows 平台

即使应用在自动升级前已关闭,在特殊情况下(如后台服务未退出)仍可能出现文件占用。此时可使用微软的 **handle.exe** 工具检查指定目录下是否有进程在运行。

`handle.exe` 是 Microsoft Sysinternals 提供的命令行工具,用于显示哪些进程打开了指定文件。在 C# 中可通过 `System.Diagnostics.Process` 调用。

```csharp
using System;
using System.Diagnostics;

class Program
{
static void Main()
{
Process process = new Process();
process.StartInfo.FileName = "handle.exe";
process.StartInfo.Arguments = "filename"; // 替换为实际的文件或目录路径
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();

string output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);

process.WaitForExit();
}
}
```

**如果仍存在文件占用:**
1. 检查是否有后台服务未关闭
2. 使用 `handle.exe` 排查占用进程
3. 考虑使用强制终止或重启后更新策略

**参考链接:**
- [Handle - Sysinternals](https://learn.microsoft.com/zh-cn/sysinternals/downloads/handle)

---

## 七、崩溃转储诊断

在自动更新过程中,如果更新失败或更新后程序崩溃,可使用 **ProcDump** 工具导出 dump 文件进行分析。

ProcDump 是 Microsoft Sysinternals 的命令行实用工具,主要用于监控应用程序的 CPU 峰值并在峰值期间生成崩溃转储。管理员或开发人员可使用这些转储来确定崩溃原因。ProcDump 还支持挂起窗口监控、未处理异常监控,并可基于系统性能计数器值生成转储。

### C# 调用 ProcDump

```csharp
using System;
using System.Diagnostics;

public class Program
{
public static void Main()
{
var procDumpPath = @"C:\Path\To\procdump.exe";
var processId = 1234; // 需要 dump 的进程 ID
var dumpFilePath = @"C:\Path\To\dumpfile.dmp";

var startInfo = new ProcessStartInfo
{
FileName = procDumpPath,
Arguments = $"-ma {processId} {dumpFilePath}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};

var process = new Process { StartInfo = startInfo };
process.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (sender, e) => Console.Error.WriteLine(e.Data);

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();

process.WaitForExit();
}
}
```

**参考链接:**
- [ProcDump - Sysinternals](https://learn.microsoft.com/zh-cn/sysinternals/downloads/procdump)

---

## 八、版本号管理

### 推荐策略

Expand All @@ -261,7 +421,7 @@ jobs:

---

## 六、检查清单
## 九、部署检查清单

部署前确认:

Expand All @@ -280,6 +440,5 @@ jobs:
## 相关资源

- **[GeneralUpdate.Tools](../quickstart/GeneralUpdate.PacketTool)** — 补丁包和配置生成工具
- **[权限指南](./Permission)** — Windows UAC 权限处理
- **[入门实战手册](../quickstart/Beginner%20cookbook)** — 从零跑通更新闭环
- **[入门实战手册](../quickstart/Beginner cookbook)** — 从零跑通更新闭环
- **[GeneralUpdate.Core](../doc/GeneralUpdate.Core)** — 核心更新引擎架构
50 changes: 0 additions & 50 deletions website/docs/guide/Dump.md

This file was deleted.

Loading
Loading