|
@@ -18,13 +18,21 @@ Future<void> killProcess(String name) async {
|
|
|
|
|
|
Future<bool> isRunningAsAdmin() async {
|
|
|
final Shell shell = Shell();
|
|
|
- // 使用 "net session" 命令,如果成功,则意味着我们有管理员权限
|
|
|
- final List<ProcessResult> result = await shell.run('net session');
|
|
|
- if (result.isNotEmpty && result[0].exitCode == 0) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
+
|
|
|
+ try {
|
|
|
+ // Attempt the "net session" command.
|
|
|
+ final List<ProcessResult> results = await shell.run('net session');
|
|
|
+
|
|
|
+ // Check the exit code of the first result.
|
|
|
+ if (results.isNotEmpty && results[0].exitCode == 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // If any exception is thrown (like ShellException), we assume we don't have admin rights.
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
Future<ProcessResult> runAsAdmin(String executable, List<String> arguments) async {
|