回滚动态UAC

This commit is contained in:
2023-11-13 22:52:40 +08:00
parent 2594f85f25
commit b6f0728e2c
7 changed files with 12 additions and 93 deletions

View File

@ -17,7 +17,7 @@ import 'package:window_manager/window_manager.dart';
import '../base/ui.dart';
class AppConf {
static const String appVersion = "2.9.13 Beta";
static const String appVersion = "2.9.14 Beta";
static const int appVersionCode = 28;
static const String appVersionDate = "2023-11-11";
@ -40,8 +40,6 @@ class AppConf {
static bool offlineMode = false;
static bool isRunningAdmin = false;
static late final WindowsDeviceInfo windowsDeviceInfo;
static Color? colorBackground;
@ -83,7 +81,6 @@ class AppConf {
}
dPrint("---- rust bridge inited -----");
await SystemHelper.initPowershellPath();
isRunningAdmin = await globalUIModel.checkAdmin();
/// init defaultColor
colorBackground = HexColor("#132431").withOpacity(.75);

View File

@ -1,6 +1,5 @@
import 'dart:io';
import 'package:starcitizen_doctor/common/conf.dart';
import 'package:starcitizen_doctor/common/utils/base_utils.dart';
class SystemHelper {
@ -44,7 +43,7 @@ class SystemHelper {
}
static Future<String> addNvmePatch() async {
var result = await powershellAdminRun([
var result = await Process.run(powershellPath, [
'New-ItemProperty',
"-Path",
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
@ -60,7 +59,7 @@ class SystemHelper {
static doRemoveNvmePath() async {
try {
var result = await powershellAdminRun([
var result = await Process.run(powershellPath, [
"Clear-ItemProperty",
"-Path",
"\"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\stornvme\\Parameters\\Device\"",
@ -202,40 +201,4 @@ foreach ($adapter in $adapterMemory) {
} catch (_) {}
return totalSize;
}
static Future<ProcessResult> powershellAdminRun(List<String> args) async {
// 创建 PowerShell 脚本文件
final scriptContent = """
${args.join(' ')}
""";
// 将脚本内容写入临时文件
final scriptFile =
File('${AppConf.applicationSupportDir}\\temp\\psh_script.ps1');
if (await scriptFile.exists()) {
await scriptFile.delete();
}
if (!await scriptFile.exists()) {
await scriptFile.create(recursive: true);
}
await scriptFile.writeAsString(scriptContent);
List<String> command = [
'Start-Process',
'powershell.exe',
'-Verb RunAs',
'-ArgumentList',
"'-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File','${scriptFile.absolute.path}'",
'-Wait',
'-PassThru '
];
final r = await Process.run(
'powershell.exe',
command,
runInShell: true,
);
await scriptFile.delete();
return r;
}
}