-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPowerShellHelper.cs
More file actions
49 lines (43 loc) · 1.59 KB
/
PowerShellHelper.cs
File metadata and controls
49 lines (43 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Diagnostics;
namespace ReWindows
{
public static class PowerShellHelper
{
public static bool IsAppInstalled(string packageName)
{
string result = RunPowerShell($"Get-AppxPackage -Name '*{packageName}*' | Select-Object -ExpandProperty Name");
return !string.IsNullOrWhiteSpace(result);
}
public static void RemoveApp(string packageName)
{
RunPowerShell($"Get-AppxPackage -Name '*{packageName}*' | Remove-AppxPackage");
}
public static void ReinstallApp(string winGetId)
{
var startInfo = new ProcessStartInfo
{
FileName = "winget",
Arguments = $"install --id {winGetId} --silent --accept-source-agreements --accept-package-agreements",
UseShellExecute = false,
CreateNoWindow = true
};
using var process = Process.Start(startInfo);
process?.WaitForExit();
}
private static string RunPowerShell(string command)
{
var startInfo = new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -NonInteractive -Command \"{command}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using var process = Process.Start(startInfo);
string output = process?.StandardOutput.ReadToEnd() ?? "";
process?.WaitForExit();
return output;
}
}
}