-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForm2.cs
More file actions
115 lines (103 loc) · 4.03 KB
/
Form2.cs
File metadata and controls
115 lines (103 loc) · 4.03 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Diagnostics;
using System.Windows.Forms;
using ProcessPrivileges;
using System.Runtime.InteropServices;
//checkedListBox1.Items[i] = "string";
//checkedListBox1.GetItemChecked(i);
//checkedListBox1.SetItemChecked(i, true);
namespace MBST_Lab_1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Process SelectedProcess;
bool[] temp;
public void start_check_privileges(string ProcessID)
{
GetWorkPrivilegesList();
SelectedProcess = Process.GetProcessById(Convert.ToInt32(ProcessID));
Form1 Form1 = new Form1();
string ProcessPrivileges = Form1.GetProcessPriveleges(SelectedProcess);
temp = new bool[checkedListBox1.Items.Count];
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (ProcessPrivileges.Contains(checkedListBox1.Items[i].ToString()))
{
checkedListBox1.SetItemChecked(i, true);
temp[i] = true;
}
else
temp[i] = false;
}
}
private void SetButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i) == true && temp[i] == false)
{
try { SelectedProcess.EnablePrivilege(AllPrivileges[i]); }
catch { }
}
else if (checkedListBox1.GetItemChecked(i) == false && temp[i] == true)
{
try { SelectedProcess.DisablePrivilege(AllPrivileges[i]); }
catch { }
}
}
}
Privilege[] AllPrivileges;
private void GetWorkPrivilegesList()
{
AllPrivileges = new Privilege[checkedListBox1.Items.Count];
AllPrivileges[0] = Privilege.ChangeNotify;
AllPrivileges[1] = Privilege.Security;
AllPrivileges[2] = Privilege.Backup;
AllPrivileges[3] = Privilege.Restore;
AllPrivileges[4] = Privilege.SystemTime;
AllPrivileges[5] = Privilege.Shutdown;
AllPrivileges[6] = Privilege.RemoteShutdown;
AllPrivileges[7] = Privilege.TakeOwnership;
AllPrivileges[8] = Privilege.Debug;
AllPrivileges[9] = Privilege.SystemEnvironment;
AllPrivileges[10] = Privilege.SystemProfile;
AllPrivileges[11] = Privilege.ProfileSingleProcess;
AllPrivileges[12] = Privilege.IncreaseBasePriority;
AllPrivileges[13] = Privilege.LoadDriver;
AllPrivileges[14] = Privilege.CreatePageFile;
AllPrivileges[15] = Privilege.IncreaseQuota;
AllPrivileges[16] = Privilege.Undock;
AllPrivileges[17] = Privilege.ManageVolume;
AllPrivileges[18] = Privilege.Impersonate;
AllPrivileges[19] = Privilege.CreateGlobal;
}
private void SetAllButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
checkedListBox1.SetItemChecked(i, true);
}
private void DeleteAllButton_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
checkedListBox1.SetItemChecked(i, false);
}
[DllImport("C:\\Users\\dzaga\\Desktop\\MBST_Lab_1\\Level.dll")]
public static extern bool SetIntegrityLevel(int privilegeLevel, int ID);
private void Low_Click(object sender, EventArgs e)
{
SetIntegrityLevel(1, SelectedProcess.Id);
}
private void Medium_Click(object sender, EventArgs e)
{
SetIntegrityLevel(2, SelectedProcess.Id);
}
private void High_Click(object sender, EventArgs e)
{
SetIntegrityLevel(3, SelectedProcess.Id);
}
}
}