Skip to content
This repository was archived by the owner on Jun 23, 2022. It is now read-only.

Commit 7b074e9

Browse files
committed
Removed administartor manifest
1 parent 841b6ba commit 7b074e9

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

DNSChanger/DNSChangeDetectedForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ private void manualBtn_Click(object sender, EventArgs e)
4343
{
4444
StartInfo = new ProcessStartInfo
4545
{
46-
FileName = Process.GetCurrentProcess().MainModule.FileName,
46+
FileName = Utilities.GetProcessPath(),
47+
UseShellExecute = true,
4748
Verb = "runas",
48-
UseShellExecute = false,
4949
},
5050
};
5151

DNSChanger/DNSChanger.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<Compile Include="Structs\DNSEntry.cs" />
9595
<Compile Include="Structs\DNSServerEntry.cs" />
9696
<Compile Include="Structs\Interface.cs" />
97+
<Compile Include="Utilities.cs" />
9798
<EmbeddedResource Include="DNSChangeDetectedForm.resx">
9899
<DependentUpon>DNSChangeDetectedForm.cs</DependentUpon>
99100
</EmbeddedResource>

DNSChanger/DNSValidate.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
using DNSChanger.Structs;
22
using Microsoft.Win32.TaskScheduler;
33
using System;
4-
using System.Diagnostics;
54
using System.Linq;
65
using System.Text.RegularExpressions;
76

87
namespace DNSChanger
98
{
109
public static class DNSValidate
1110
{
12-
private const string TaskPath = "DNSChanger-ValidationTask";
11+
private static readonly string TaskPath = GlobalVars.Name + "-ValidationTask";
1312

1413
static DNSValidate()
1514
{
16-
if (!VerifyProcessPath())
15+
if (!ValidateAutoStartProcessPath())
1716
{
1817
var @interface = GetInterfaceToValidate();
1918
if (@interface.HasValue)
@@ -52,14 +51,14 @@ private static Task Get()
5251
return TaskService.Instance.GetTask(TaskPath);
5352
}
5453

55-
private static bool VerifyProcessPath()
54+
private static bool ValidateAutoStartProcessPath()
5655
{
5756
var tsk = Get();
5857
if (tsk == null) return true;
5958

6059
var action = (ExecAction) tsk.Definition.Actions[0];
6160

62-
return action.Path == Process.GetCurrentProcess().MainModule.FileName;
61+
return action.Path == Utilities.GetProcessPath();
6362
}
6463

6564
public static Interface? GetInterfaceToValidate()
@@ -111,8 +110,9 @@ public static void Enable(Interface @interface)
111110
var task = ts.NewTask();
112111
task.Principal.RunLevel = TaskRunLevel.Highest;
113112
task.RegistrationInfo.Description = "Performs DNS validation procedure on boot";
113+
task.RegistrationInfo.Author = GlobalVars.Name;
114114
task.Triggers.Add(new BootTrigger());
115-
task.Actions.Add(Process.GetCurrentProcess().MainModule.FileName, $"-validate \"{@interface.Name}\" \"{AggregateDnsEntries(@interface)}\"");
115+
task.Actions.Add(Utilities.GetProcessPath(), $"-validate \"{@interface.Name}\" \"{AggregateDnsEntries(@interface)}\"");
116116

117117
ts.RootFolder.RegisterTaskDefinition(TaskPath, task);
118118
}

DNSChanger/Program.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Linq;
4+
using System.Security.Principal;
35
using System.Windows.Forms;
46

57
namespace DNSChanger
@@ -9,6 +11,22 @@ public static class Program
911
[STAThread]
1012
public static void Main(string[] args)
1113
{
14+
if (!Utilities.IsAdministrator())
15+
{
16+
var proc = new Process
17+
{
18+
StartInfo = new ProcessStartInfo
19+
{
20+
FileName = Utilities.GetProcessPath(),
21+
UseShellExecute = true,
22+
Verb = "runas",
23+
},
24+
};
25+
26+
proc.Start();
27+
return;
28+
}
29+
1230
Application.EnableVisualStyles();
1331
Application.SetCompatibleTextRenderingDefault(false);
1432

DNSChanger/Utilities.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Diagnostics;
2+
using System.Security.Principal;
3+
4+
namespace DNSChanger
5+
{
6+
public static class Utilities
7+
{
8+
public static bool IsAdministrator()
9+
{
10+
using (var identity = WindowsIdentity.GetCurrent())
11+
{
12+
var principal = new WindowsPrincipal(identity);
13+
return principal.IsInRole(WindowsBuiltInRole.Administrator);
14+
}
15+
}
16+
17+
public static string GetProcessPath()
18+
{
19+
return Process.GetCurrentProcess().MainModule.FileName;
20+
}
21+
}
22+
}

DNSChanger/app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Remove this element if your application requires this virtualization for backwards
1717
compatibility.
1818
-->
19-
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
19+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
2020
</requestedPrivileges>
2121
</security>
2222
</trustInfo>

0 commit comments

Comments
 (0)