-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
74 lines (68 loc) · 2.43 KB
/
Program.cs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Management.Automation;
using Virtu_Toggler;
using var ps = PowerShell.Create();
try
{
// The script path that checks the registry if the hypervisor is on.
ps.AddScript("(Get-ItemProperty -Path \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\\DeviceGuard\\Scenarios\\HypervisorEnforcedCodeIntegrity\")");
var result = ps.Invoke();
// Runs function that checks if the script gave off errors
VirtuChanger.PSErrorCheck(ps);
string decision = "";
string mode = "";
// Iterates through results, to find if "Enabled" is 1 or 0.
foreach (PSObject value in result)
{
object enabled = value.Properties["Enabled"].Value;
if (enabled.ToString() == "1")
{
mode = enabled.ToString();
// If virtualization is enabled.
Console.WriteLine("Virtualization is turned on, do you wish to turn it off? (y/n)");
decision = Console.ReadLine();
while (decision != "n" && decision != "N" && decision != "y" && decision != "Y")
{
Console.WriteLine("Wrong input, try again (y means yes, n means no)");
decision = Console.ReadLine();
}
// No changes made.
if(decision == "n" || decision == "N")
{
Console.WriteLine("Stopping program...");
break;
}
// Disable virtualization
else
{
VirtuChanger.Toggler(mode);
}
}
else if (enabled.ToString() == "0")
{
mode = enabled.ToString();
// If virtualization is disabled.
Console.WriteLine("Virtualization is turned off, do you wish to turn it on? (y/n)");
decision = Console.ReadLine();
while (decision != "n" && decision != "N" && decision != "y" && decision != "Y")
{
Console.WriteLine("Wrong input, try again (y means yes, n means no)");
decision = Console.ReadLine();
}
// No changes made.
if (decision == "n" || decision == "N")
{
Console.WriteLine("Stopping program...");
break;
}
// Enable virtualization.
else
{
VirtuChanger.Toggler(mode);
}
}
}
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}