improve:PPT联动
This commit is contained in:
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"Codegeex.RepoIndex": true
|
||||
}
|
||||
+363
-7
@@ -123,11 +123,27 @@ namespace Ink_Canvas
|
||||
if (baseKey == null)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"注册表路径不存在: {regPath}", LogHelper.LogType.Warning);
|
||||
// 尝试创建路径
|
||||
try
|
||||
{
|
||||
using (Microsoft.Win32.RegistryKey createKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(regPath, true))
|
||||
{
|
||||
if (createKey != null)
|
||||
{
|
||||
createKey.SetValue("DisableProtectedView", 1, Microsoft.Win32.RegistryValueKind.DWord);
|
||||
LogHelper.WriteLogToFile($"创建并设置注册表路径: {regPath}", LogHelper.LogType.Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception createEx)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"创建注册表路径失败: {createEx.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Settings settingsInstance = new Settings();
|
||||
string backupPath = Path.Combine(settingsInstance.Automation.AutoSavedStrokesLocation, "RegistryBackups");
|
||||
// 备份路径更改为软件根目录下的saves/RegistryBackups文件夹
|
||||
string backupPath = Path.Combine(RootPath, "saves", "RegistryBackups");
|
||||
LogHelper.WriteLogToFile($"备份路径: {backupPath}");
|
||||
|
||||
if (!Directory.Exists(backupPath))
|
||||
@@ -176,6 +192,9 @@ namespace Ink_Canvas
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理Office 365的特殊路径
|
||||
TryModifyOffice365Registry();
|
||||
}
|
||||
catch (SecurityException secEx)
|
||||
{
|
||||
@@ -321,14 +340,72 @@ namespace Ink_Canvas
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查注册表判断Office是否存在
|
||||
// 检查多个可能的注册表路径
|
||||
// 1. 检查传统的Office版本
|
||||
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office"))
|
||||
{
|
||||
return key?.GetValueNames().Any(name => name.Contains(".0")) ?? false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
if (key != null && key.GetSubKeyNames().Any(name => name.Contains(".0")))
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到传统Office安装", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 检查64位注册表中的Office
|
||||
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\Microsoft\\Office"))
|
||||
{
|
||||
if (key != null && key.GetSubKeyNames().Any(name => name.Contains(".0")))
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到64位注册表中的Office安装", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检查Office 365/Click-to-Run安装
|
||||
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\ClickToRun"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到Office 365 Click-to-Run", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 检查Office 365部署配置
|
||||
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\15.0\\ClickToRun"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到Office 365 (15.0)", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\16.0\\ClickToRun"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到Office 365 (16.0)", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 检查Office 365零售订阅信息
|
||||
using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\ClickToRun\\Configuration"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到Office 365配置", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile("未检测到任何Office安装", LogHelper.LogType.Warning);
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"检查Office安装时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -398,6 +475,16 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查Office 365的特殊路径
|
||||
CheckOffice365Versions(versions);
|
||||
|
||||
// 如果没有找到任何版本,添加默认的Office 365版本号
|
||||
if (versions.Count == 0 && IsOffice365Installed())
|
||||
{
|
||||
versions.Add("16.0");
|
||||
LogHelper.WriteLogToFile("未找到具体版本,添加默认Office 365版本: 16.0");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -421,5 +508,274 @@ namespace Ink_Canvas
|
||||
|
||||
return versions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测Office 365是否已安装
|
||||
/// </summary>
|
||||
private bool IsOffice365Installed()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查多个Office 365特定路径
|
||||
using (var key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\ClickToRun"))
|
||||
{
|
||||
if (key != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
using (var key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\15.0\\ClickToRun"))
|
||||
{
|
||||
if (key != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
using (var key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\16.0\\ClickToRun"))
|
||||
{
|
||||
if (key != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
using (var key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\ClickToRun\\Configuration"))
|
||||
{
|
||||
if (key != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查Office 365特有的版本信息
|
||||
/// </summary>
|
||||
private void CheckOffice365Versions(List<string> versions)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查Click-to-Run版本路径
|
||||
using (var key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Office\\ClickToRun\\Configuration"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
var platformVersion = key.GetValue("Platform") as string;
|
||||
var clickToRunVersion = key.GetValue("VersionToReport") as string;
|
||||
|
||||
if (!string.IsNullOrEmpty(platformVersion))
|
||||
{
|
||||
var majorVersion = platformVersion.Split('.').FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(majorVersion) && !versions.Contains($"{majorVersion}.0"))
|
||||
{
|
||||
versions.Add($"{majorVersion}.0");
|
||||
LogHelper.WriteLogToFile($"在Office 365配置中找到平台版本: {majorVersion}.0");
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(clickToRunVersion))
|
||||
{
|
||||
var majorVersion = clickToRunVersion.Split('.').FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(majorVersion) && !versions.Contains($"{majorVersion}.0"))
|
||||
{
|
||||
versions.Add($"{majorVersion}.0");
|
||||
LogHelper.WriteLogToFile($"在Office 365配置中找到报告版本: {majorVersion}.0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查安装路径来确认版本
|
||||
var possibleVersions = new[] { "15.0", "16.0" }; // Office 2013 (15.0) 和 Office 2016/2019/365 (16.0)
|
||||
foreach (var version in possibleVersions)
|
||||
{
|
||||
using (var key = Registry.LocalMachine.OpenSubKey($"Software\\Microsoft\\Office\\{version}\\Common\\InstallRoot"))
|
||||
{
|
||||
if (key != null && key.GetValue("Path") != null && !versions.Contains(version))
|
||||
{
|
||||
versions.Add(version);
|
||||
LogHelper.WriteLogToFile($"在InstallRoot中找到Office版本: {version}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"检查Office 365版本时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试修改Office 365的特殊注册表路径
|
||||
/// </summary>
|
||||
private void TryModifyOffice365Registry()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 准备备份目录
|
||||
string backupPath = Path.Combine(RootPath, "saves", "RegistryBackups");
|
||||
if (!Directory.Exists(backupPath))
|
||||
{
|
||||
Directory.CreateDirectory(backupPath);
|
||||
LogHelper.WriteLogToFile($"创建Office 365备份目录: {backupPath}");
|
||||
}
|
||||
|
||||
// 检查Office 365 Outlook和PowerPoint的特定路径
|
||||
string[] apps = { "outlook", "powerpoint" };
|
||||
|
||||
foreach (var app in apps)
|
||||
{
|
||||
// 检查用户级别的注册表
|
||||
string regPath = $"Software\\Microsoft\\Office\\16.0\\{app}\\Security";
|
||||
LogHelper.WriteLogToFile($"检查Office 365特定应用注册表: {regPath}");
|
||||
|
||||
try
|
||||
{
|
||||
// 先检查是否存在该路径
|
||||
using (var baseKey = Registry.CurrentUser.OpenSubKey(regPath))
|
||||
{
|
||||
// 如果路径存在,先备份
|
||||
if (baseKey != null)
|
||||
{
|
||||
string backupFile = Path.Combine(backupPath, $"SecurityBackup_365_{app}_{DateTime.Now:yyyyMMddHHmmss}.reg");
|
||||
LogHelper.WriteLogToFile($"创建Office 365 {app}备份文件: {backupFile}");
|
||||
|
||||
// 使用UTF8编码写入注册表文件
|
||||
using (StreamWriter sw = new StreamWriter(backupFile, false, System.Text.Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine("Windows Registry Editor Version 5.00\n");
|
||||
sw.WriteLine();
|
||||
sw.WriteLine($"[{Microsoft.Win32.Registry.CurrentUser.Name}\\{regPath}]");
|
||||
|
||||
foreach (string valueName in baseKey.GetValueNames())
|
||||
{
|
||||
object value = baseKey.GetValue(valueName);
|
||||
sw.WriteLine($"\"{valueName}\"=dword:{((int)value):x8}");
|
||||
LogHelper.WriteLogToFile($"备份Office 365 {app}注册表值: {valueName} = {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改或创建注册表项
|
||||
using (var key = Registry.CurrentUser.CreateSubKey(regPath, true))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
object currentValue = key.GetValue("DisableProtectedView");
|
||||
if (currentValue == null || (int)currentValue != 1)
|
||||
{
|
||||
key.SetValue("DisableProtectedView", 1, RegistryValueKind.DWord);
|
||||
LogHelper.WriteLogToFile($"Office 365 {app} 注册表值已设置: DisableProtectedView = 1");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogToFile($"Office 365 {app} 注册表值已存在且无需更改");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"修改 {app} 注册表时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试通过Office信任中心路径修改
|
||||
string trustCenterPath = "Software\\Microsoft\\Office\\16.0\\Common\\Security\\FileValidation";
|
||||
LogHelper.WriteLogToFile($"检查信任中心路径: {trustCenterPath}");
|
||||
|
||||
try
|
||||
{
|
||||
// 先检查是否存在该路径
|
||||
using (var baseKey = Registry.CurrentUser.OpenSubKey(trustCenterPath))
|
||||
{
|
||||
// 如果路径存在,先备份
|
||||
if (baseKey != null)
|
||||
{
|
||||
string backupFile = Path.Combine(backupPath, $"SecurityBackup_365_TrustCenter_{DateTime.Now:yyyyMMddHHmmss}.reg");
|
||||
LogHelper.WriteLogToFile($"创建信任中心备份文件: {backupFile}");
|
||||
|
||||
// 使用UTF8编码写入注册表文件
|
||||
using (StreamWriter sw = new StreamWriter(backupFile, false, System.Text.Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine("Windows Registry Editor Version 5.00\n");
|
||||
sw.WriteLine();
|
||||
sw.WriteLine($"[{Microsoft.Win32.Registry.CurrentUser.Name}\\{trustCenterPath}]");
|
||||
|
||||
foreach (string valueName in baseKey.GetValueNames())
|
||||
{
|
||||
object value = baseKey.GetValue(valueName);
|
||||
sw.WriteLine($"\"{valueName}\"=dword:{((int)value):x8}");
|
||||
LogHelper.WriteLogToFile($"备份信任中心注册表值: {valueName} = {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var key = Registry.CurrentUser.CreateSubKey(trustCenterPath, true))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
key.SetValue("DisableEditFromPV", 1, RegistryValueKind.DWord);
|
||||
LogHelper.WriteLogToFile("已禁用受保护视图中的编辑");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"修改信任中心路径时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
|
||||
// 尝试修改EnableEditWhileViewingPolicy
|
||||
string policyPath = "Software\\Policies\\Microsoft\\Office\\16.0\\Common\\Security";
|
||||
try
|
||||
{
|
||||
// 先检查是否存在该路径
|
||||
using (var baseKey = Registry.CurrentUser.OpenSubKey(policyPath))
|
||||
{
|
||||
// 如果路径存在,先备份
|
||||
if (baseKey != null)
|
||||
{
|
||||
string backupFile = Path.Combine(backupPath, $"SecurityBackup_365_Policy_{DateTime.Now:yyyyMMddHHmmss}.reg");
|
||||
LogHelper.WriteLogToFile($"创建策略备份文件: {backupFile}");
|
||||
|
||||
// 使用UTF8编码写入注册表文件
|
||||
using (StreamWriter sw = new StreamWriter(backupFile, false, System.Text.Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine("Windows Registry Editor Version 5.00\n");
|
||||
sw.WriteLine();
|
||||
sw.WriteLine($"[{Microsoft.Win32.Registry.CurrentUser.Name}\\{policyPath}]");
|
||||
|
||||
foreach (string valueName in baseKey.GetValueNames())
|
||||
{
|
||||
object value = baseKey.GetValue(valueName);
|
||||
sw.WriteLine($"\"{valueName}\"=dword:{((int)value):x8}");
|
||||
LogHelper.WriteLogToFile($"备份策略注册表值: {valueName} = {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var key = Registry.CurrentUser.CreateSubKey(policyPath, true))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
key.SetValue("EnableEditWhileViewingPolicy", 1, RegistryValueKind.DWord);
|
||||
LogHelper.WriteLogToFile("已启用查看时编辑策略");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"修改策略路径时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"修改Office 365注册表时发生未知错误: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user