update powershell path
This commit is contained in:
parent
8e0f79e28e
commit
9777afe02d
2 changed files with 24 additions and 17 deletions
|
|
@ -127,12 +127,20 @@ class ProcessData {
|
|||
}
|
||||
|
||||
class ProcessExecutor {
|
||||
static bool _powershellGranted = false;
|
||||
static Future getPowershellGrant() async {
|
||||
if (!_powershellGranted) {
|
||||
_powershellGranted = true;
|
||||
var result = await Process.run(
|
||||
'powershell.exe',
|
||||
static String _powershellPath = '';
|
||||
static Future<String> getPowershell() async {
|
||||
if (_powershellPath.isEmpty) {
|
||||
var result = await Process.run('cmd', ['/c', 'where powershell']);
|
||||
if (result.exitCode == 0) {
|
||||
var path = result.stdout.toString().split('\n')[0];
|
||||
_powershellPath = File(path).absolute.path;
|
||||
}
|
||||
if (_powershellPath.isEmpty) {
|
||||
throw UnsupportedError('Not found powershell');
|
||||
}
|
||||
|
||||
result = await Process.run(
|
||||
_powershellPath,
|
||||
[
|
||||
'-Command',
|
||||
'Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned'
|
||||
|
|
@ -144,7 +152,7 @@ class ProcessExecutor {
|
|||
print('[Powershell Grant] Error: ${result.stderr}');
|
||||
}
|
||||
}
|
||||
return simpleFuture;
|
||||
return dataFutrue(_powershellPath);
|
||||
}
|
||||
|
||||
static Future<ProcessData> startExe(String exe, List<String> args,
|
||||
|
|
@ -226,11 +234,9 @@ class ProcessExecutor {
|
|||
file.createSync();
|
||||
file.writeAsStringSync(shell.toString(), flush: true);
|
||||
|
||||
await getPowershellGrant();
|
||||
|
||||
try {
|
||||
processData.process = await Process.start(
|
||||
'powershell.exe', ['-NoProfile', '-File', file.absolute.path]);
|
||||
processData.process = await Process.start(await getPowershell(),
|
||||
['-NoProfile', '-File', file.absolute.path]);
|
||||
} on Exception catch (e) {
|
||||
logHandler ?? (e, LogType.error);
|
||||
}
|
||||
|
|
@ -288,10 +294,10 @@ class ProcessExecutor {
|
|||
|
||||
print(file.absolute.path);
|
||||
|
||||
await getPowershellGrant();
|
||||
await getPowershell();
|
||||
|
||||
processResult = await Process.run(
|
||||
'powershell.exe', // PowerShell 실행
|
||||
await getPowershell(), // PowerShell 실행
|
||||
['-NoProfile', '-File', file.absolute.path],
|
||||
runInShell: true);
|
||||
|
||||
|
|
|
|||
|
|
@ -324,7 +324,8 @@ Exit
|
|||
@override
|
||||
Future<bool> isRegistedStartup(String label) async {
|
||||
var shell = 'Get-ScheduledTask | Where-Object {\$_.TaskName -eq "$label"}';
|
||||
var process = await Process.run('powershell.exe', [shell]);
|
||||
var process =
|
||||
await Process.run(await ProcessExecutor.getPowershell(), [shell]);
|
||||
var exist = false;
|
||||
if (process.exitCode == 0) {
|
||||
var existLine = <String>[];
|
||||
|
|
@ -387,8 +388,8 @@ Exit
|
|||
var powershellCommand =
|
||||
'Start-Process powershell.exe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `& \'${tempFile.path}\'; exit" -Verb RunAs -WindowStyle Hidden';
|
||||
|
||||
var process = await Process.run(
|
||||
'powershell', ['-Command', powershellCommand, '-Wait']);
|
||||
var process = await Process.run(await ProcessExecutor.getPowershell(),
|
||||
['-Command', powershellCommand, '-Wait']);
|
||||
|
||||
print(process.stdout.toString());
|
||||
print(process.stderr.toString());
|
||||
|
|
@ -403,7 +404,7 @@ Exit
|
|||
Future<bool> unregistStartup(String label) async {
|
||||
var shell = 'Unregister-ScheduledTask -TaskName "$label" -Confirm:\$false';
|
||||
var process = await Process.run(
|
||||
'powershell.exe',
|
||||
await ProcessExecutor.getPowershell(),
|
||||
[
|
||||
'-Command',
|
||||
'Start-Process powershell -ArgumentList \'-NoProfile -ExecutionPolicy Bypass -Command "$shell"\' -Verb RunAs -WindowStyle Hidden'
|
||||
|
|
|
|||
Loading…
Reference in a new issue