-
Notifications
You must be signed in to change notification settings - Fork 2
/
ServicesDetail.cs
69 lines (56 loc) · 1.97 KB
/
ServicesDetail.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
using System;
using System.IO;
using System.Linq;
using System.Security.Permissions;
using System.Security.Policy;
using System.Security.Principal;
using System.ServiceProcess;
using Microsoft.Win32;
namespace TaskSchedulerConfig
{
class ServicesDetail : IDisposable
{
private WindowsIdentity id;
public SecurityIdentifier sid;
private WindowsPrincipal prin;
private string server = null;
private Firewall fw = null;
private ServiceController sc = null;
public ServicesDetail(string svr = null)
{
server = svr;
id = WindowsIdentity.GetCurrent();
sid = new SecurityIdentifier(id.User.Value);
prin = new WindowsPrincipal(id);
}
public bool UserIsAdmin => prin.IsInRole(WindowsBuiltInRole.Administrator);
public bool UserIsBackupOperator => prin.IsInRole(WindowsBuiltInRole.BackupOperator);
public bool UserIsServerOperator => prin.IsInRole(WindowsBuiltInRole.SystemOperator);
public bool V1TaskPathAccess
{
get
{
try
{
new FileIOPermission(FileIOPermissionAccess.AllAccess, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Tasks")).Demand();
return true;
}
catch { }
return false;
}
}
public Firewall Firewall => fw ?? (fw = new Firewall(server));
public bool IsLocal => string.IsNullOrEmpty(server);
public ServiceController RemoteRegistryService => sc ?? (sc = new ServiceController("RemoteRegistry", server ?? "."));
public string Server => server;
public string User => id.Name;
public LocalSecurity.Rights UserRights => new LocalSecurity(Server).UserAccountRights(User);
public LocalSecurity.SystemAccess UserAccessRights => new LocalSecurity(Server).UserSystemAccess(User);
public bool RemoteRegistryServiceRunning => RemoteRegistryService.Status == ServiceControllerStatus.Running;
void IDisposable.Dispose()
{
if (sc != null) { sc.Close(); sc = null; }
if (fw != null) { fw = null; }
}
}
}