wasSharpNET – Diff between revs 26 and 27
?pathlinks?
Rev 26 | Rev 27 | |||
---|---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////// |
|
2 | // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // |
2 | // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // |
|
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
|
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
|
5 | /////////////////////////////////////////////////////////////////////////// |
5 | /////////////////////////////////////////////////////////////////////////// |
|
6 | |
6 | |
|
7 | using System; |
7 | using System; |
|
8 | using System.Diagnostics; |
8 | using System.Diagnostics; |
|
9 | using System.Linq; |
9 | using System.Linq; |
|
10 | using System.Reflection; |
10 | using System.Reflection; |
|
11 | |
11 | |
|
12 | namespace wasSharpNET.Platform.Windows |
12 | namespace wasSharpNET.Platform.Windows |
|
13 | { |
13 | { |
|
14 | public static class Utilities |
14 | public static class Utilities |
|
15 | { |
15 | { |
|
16 | public static bool ElevatePrivileges() |
16 | public static bool ElevatePrivileges() |
|
17 | { |
17 | { |
|
18 | try |
18 | try |
|
19 | { |
19 | { |
|
20 | // Create an elevated process with the original arguments. |
20 | // Create an elevated process with the original arguments. |
|
21 | var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location, |
21 | var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location, |
|
22 | string.Join(@" ", Environment.CommandLine.Split(' ').Skip(1))) |
22 | string.Join(@" ", Environment.CommandLine.Split(' ').Skip(1))) |
|
23 | { |
23 | { |
|
24 | Verb = "runas" // indicates to elevate privileges |
24 | Verb = "runas" // indicates to elevate privileges |
|
25 | }; |
25 | }; |
|
26 | |
26 | |
|
27 | var process = new System.Diagnostics.Process |
27 | var process = new System.Diagnostics.Process |
|
28 | { |
28 | { |
|
29 | EnableRaisingEvents = true, // enable WaitForExit() |
29 | EnableRaisingEvents = true, // enable WaitForExit() |
|
30 | StartInfo = info |
30 | StartInfo = info |
|
31 | }; |
31 | }; |
|
32 | |
32 | |
|
33 | process.Start(); |
33 | process.Start(); |
|
34 | process.WaitForExit(); |
34 | process.WaitForExit(); |
|
35 | } |
35 | } |
|
36 | catch (Exception) |
36 | catch (Exception) |
|
37 | { |
37 | { |
|
38 | return false; |
38 | return false; |
|
39 | } |
39 | } |
|
40 | |
40 | |
|
41 | return true; |
41 | return true; |
|
42 | } |
42 | } |
|
- | 43 | |
||
- | 44 | public static bool isWindows() |
||
- | 45 | { |
||
- | 46 | return Environment.OSVersion.Platform.Equals(PlatformID.Win32NT) || |
||
- | 47 | Environment.OSVersion.Platform.Equals(PlatformID.Win32S) || |
||
- | 48 | Environment.OSVersion.Platform.Equals(PlatformID.Win32Windows) || |
||
- | 49 | Environment.OSVersion.Platform.Equals(PlatformID.WinCE); |
||
- | 50 | } |
||
43 | } |
51 | } |
|
44 | } |
52 | } |
|
45 | |
53 | |
|
46 |
|
54 |
|
|
47 | |
55 | |
|
48 | |
56 | |
|
49 | |
57 | |