-
Notifications
You must be signed in to change notification settings - Fork 0
/
Engine.cs
63 lines (56 loc) · 2.16 KB
/
Engine.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
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
namespace UacControlPanel
{
public class Engine
{
public enum STATO_UAC { DISABILITATO=0, ABILITATO=1 };
public enum STATO_ELEVAMENTO { DISABILITATO=0, PASSWORD=1, ABILITATO=2 };
STATO_UAC statoUac;
STATO_ELEVAMENTO statoElevamento;
private RegistryKey chiave;
public Engine() {
verificaSistema();
chiave=Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
int uac=(int) chiave.GetValue("EnableLUA");
int elevamento=(int) chiave.GetValue("ConsentPromptBehaviorAdmin", 2);
statoUac=(STATO_UAC) Enum.ToObject(typeof(STATO_UAC), uac);
statoElevamento=(STATO_ELEVAMENTO) Enum.ToObject(typeof(STATO_ELEVAMENTO), elevamento);
}
private void verificaSistema()
{
System.OperatingSystem os;
os = System.Environment.OSVersion;
if (os.Platform != System.PlatformID.Win32NT || os.Version.Major != 6 || os.Version.Minor != 0)
throw new Exception("Sistema operativo non supportato.");
}
public STATO_UAC getUac() { return statoUac; }
public STATO_ELEVAMENTO getElevamento() {return statoElevamento;}
public bool disabilitaUac()
{
bool riavvio = false;
if (statoUac != STATO_UAC.DISABILITATO)
{
riavvio = true;
chiave.SetValue("EnableLUA", 0);
statoUac = STATO_UAC.DISABILITATO;
}
return riavvio;
}
public bool abilitaUac(STATO_ELEVAMENTO e)
{
bool riavvio = false;
if (statoUac != STATO_UAC.ABILITATO)
{
statoUac = STATO_UAC.ABILITATO;
chiave.SetValue("EnableLUA", 1);
riavvio = true;
}
statoElevamento = e;
chiave.SetValue("ConsentPromptBehaviorAdmin", (int)e);
return riavvio;
}
}
}