Skip to content

Commit 7bc2c06

Browse files
committed
* Code cleanup
1 parent c6ce41a commit 7bc2c06

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

MemPlus/Business/UTILS/Utils.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Management;
5+
using System.Reflection;
56
using System.Security.Principal;
67
using System.Windows;
78
using MemPlus.Business.EXPORT;
@@ -37,6 +38,32 @@ internal static bool IsAdministrator()
3738
return isAdmin;
3839
}
3940

41+
/// <summary>
42+
/// Run the application using Administrative rights
43+
/// </summary>
44+
internal static void RunAsAdministrator(LogController logController)
45+
{
46+
try
47+
{
48+
Process proc = new Process
49+
{
50+
StartInfo =
51+
{
52+
FileName = Assembly.GetExecutingAssembly().Location,
53+
UseShellExecute = true,
54+
Verb = "runas"
55+
}
56+
};
57+
proc.Start();
58+
Application.Current.Shutdown();
59+
}
60+
catch (Exception ex)
61+
{
62+
logController.AddLog(new ApplicationLog(ex.Message));
63+
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
64+
}
65+
}
66+
4067
/// <summary>
4168
/// Retrieve RAM information
4269
/// </summary>

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public MainWindow()
9898
{
9999
if (Properties.Settings.Default.RunAsAdministrator)
100100
{
101-
RunAsAdministrator();
101+
Utils.RunAsAdministrator(_logController);
102102
}
103103
else if (Properties.Settings.Default.AdministrativeWarning)
104104
{
@@ -115,32 +115,6 @@ public MainWindow()
115115
_logController.AddLog(new ApplicationLog("Done initializing MainWindow"));
116116
}
117117

118-
/// <summary>
119-
/// Run the application using Administrative rights
120-
/// </summary>
121-
private void RunAsAdministrator()
122-
{
123-
try
124-
{
125-
System.Diagnostics.Process proc = new System.Diagnostics.Process
126-
{
127-
StartInfo =
128-
{
129-
FileName = Assembly.GetExecutingAssembly().Location,
130-
UseShellExecute = true,
131-
Verb = "runas"
132-
}
133-
};
134-
proc.Start();
135-
Application.Current.Shutdown();
136-
}
137-
catch (Exception ex)
138-
{
139-
_logController.AddLog(new ApplicationLog(ex.Message));
140-
MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error);
141-
}
142-
}
143-
144118
/// <summary>
145119
/// Event that is called when the GUI statistics should be updated
146120
/// </summary>

0 commit comments

Comments
 (0)