mirror of
https://github.com/wangdage12/Snap.Hutao.git
synced 2026-02-18 02:42:15 +08:00
修复以管理员权限重启问题
This commit is contained in:
@@ -193,6 +193,32 @@ internal sealed class ProcessFactory
|
||||
|
||||
public static void StartUsingShellExecuteRunAs(string fileName)
|
||||
{
|
||||
// 尝试从app包中启动
|
||||
try
|
||||
{
|
||||
global::System.Diagnostics.Process.Start(new global::System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
UseShellExecute = true,
|
||||
Verb = "runas",
|
||||
});
|
||||
}catch
|
||||
{
|
||||
// 如果失败且filename含有Snap.Hutao.Unpackaged,就直接用Snap.Hutao.exe重启
|
||||
if (fileName.Contains("Snap.Hutao.Unpackaged"))
|
||||
{
|
||||
string currentDirectory = Directory.GetCurrentDirectory();
|
||||
string unpackagedPath = Path.Combine(currentDirectory, "Snap.Hutao.exe");
|
||||
if (File.Exists(unpackagedPath))
|
||||
{
|
||||
fileName = unpackagedPath;
|
||||
}
|
||||
// 否则抛出异常
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
// 重新尝试启动
|
||||
global::System.Diagnostics.Process.Start(new global::System.Diagnostics.ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
@@ -201,3 +227,5 @@ internal sealed class ProcessFactory
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user