wasSharpNET – Diff between revs 16 and 20
?pathlinks?
Rev 16 | Rev 20 | |||
---|---|---|---|---|
Line 2... | Line 2... | |||
2 | // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // |
2 | // Copyright (C) Wizardry and Steamworks 2013 - 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 | /////////////////////////////////////////////////////////////////////////// |
|
Line -... | Line 6... | |||
- | 6 | |
||
6 | |
7 | using System.ComponentModel; |
|
- | 8 | using System.Diagnostics; |
||
7 | using System.Diagnostics; |
9 | using System.IO; |
|
8 | using System.Text; |
10 | using System.Text; |
|
- | 11 | using System.Text.RegularExpressions; |
||
Line 9... | Line 12... | |||
9 | using System.Text.RegularExpressions; |
12 | using Process = System.Diagnostics.Process; |
|
10 | |
13 | |
|
11 | namespace wasSharpNET.Platform.Windows.Commands.NetSH |
14 | namespace wasSharpNET.Platform.Windows.Commands.NetSH |
|
12 | { |
15 | { |
|
Line 26... | Line 29... | |||
26 | this.domain = domain; |
29 | this.domain = domain; |
|
27 | this.timeout = timeout; |
30 | this.timeout = timeout; |
|
Line 28... | Line 31... | |||
28 | |
31 | |
|
29 | URLReservationRegex = |
32 | URLReservationRegex = |
|
30 | new Regex( |
- | ||
31 | string.Format(@"{0}.*{1}", Regex.Escape(URL), |
33 | new Regex( |
|
32 | Regex.Escape(string.Format(@"{0}\{1}", domain, username))), |
34 | $@"{Regex.Escape(URL)}.*{Regex.Escape(string.Format(@"{0}\{1}", domain, username))}", |
|
33 | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | |
35 | RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | |
|
34 | RegexOptions.Compiled); |
36 | RegexOptions.Compiled); |
|
Line 35... | Line 37... | |||
35 | } |
37 | } |
|
Line 62... | Line 64... | |||
62 | |
64 | |
|
63 | return URLReservationRegex.IsMatch(netSHOutput.ToString()); |
65 | return URLReservationRegex.IsMatch(netSHOutput.ToString()); |
|
64 | } |
66 | } |
|
Line 65... | Line 67... | |||
65 | } |
67 | } |
|
66 | |
68 | |
|
67 | public void Reserve() |
69 | public bool Reserve() |
|
68 | { |
70 | { |
|
69 | System.Diagnostics.Process.Start(new ProcessStartInfo("netsh", |
71 | System.Diagnostics.Process process = null; |
|
- | 72 | try |
||
- | 73 | { |
||
- | 74 | process = System.Diagnostics.Process.Start(new ProcessStartInfo("netsh", |
||
70 | string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username)) |
75 | $@"http add urlacl url={URL} user={domain}\{username}") |
|
71 | { |
76 | { |
|
72 | Verb = @"runas", |
77 | Verb = @"runas", |
|
73 | CreateNoWindow = true, |
78 | CreateNoWindow = true, |
|
- | 79 | WindowStyle = ProcessWindowStyle.Hidden, |
||
- | 80 | UseShellExecute = true |
||
- | 81 | }); |
||
- | 82 | } |
||
- | 83 | catch (Win32Exception ex) |
||
- | 84 | { |
||
- | 85 | // User cancelled the UAC elevation prompt. |
||
- | 86 | if (ex.NativeErrorCode == 1223) |
||
- | 87 | { |
||
- | 88 | return false; |
||
- | 89 | } |
||
- | 90 | } |
||
- | 91 | |
||
- | 92 | if (process == null) |
||
74 | WindowStyle = ProcessWindowStyle.Hidden, |
93 | return false; |
|
75 | UseShellExecute = false |
94 | |
|
Line 76... | Line 95... | |||
76 | }).WaitForExit(timeout); |
95 | return process.WaitForExit(timeout); |
|
77 | } |
96 | } |
|
78 | |
97 | |
|
79 | public void Release() |
98 | public bool Release() |
|
80 | { |
99 | { |
|
- | 100 | System.Diagnostics.Process process = null; |
||
- | 101 | try |
||
- | 102 | { |
||
81 | System.Diagnostics.Process.Start(new ProcessStartInfo("netsh", |
103 | process = System.Diagnostics.Process.Start(new ProcessStartInfo("netsh", |
|
82 | string.Format(@"http del urlacl url={0}", URL)) |
104 | $@"http del urlacl url={URL}") |
|
83 | { |
105 | { |
|
84 | Verb = @"runas", |
106 | Verb = @"runas", |
|
- | 107 | CreateNoWindow = true, |
||
- | 108 | WindowStyle = ProcessWindowStyle.Hidden, |
||
- | 109 | UseShellExecute = true |
||
- | 110 | }); |
||
- | 111 | } |
||
- | 112 | catch (Win32Exception ex) |
||
- | 113 | { |
||
- | 114 | // User cancelled the UAC elevation prompt. |
||
- | 115 | if (ex.NativeErrorCode == 1223) |
||
- | 116 | { |
||
- | 117 | return false; |
||
- | 118 | } |
||
- | 119 | } |
||
- | 120 | |
||
85 | CreateNoWindow = true, |
121 | if (process == null) |
|
86 | WindowStyle = ProcessWindowStyle.Hidden, |
122 | return false; |
|
87 | UseShellExecute = false |
123 | |
|
88 | }).WaitForExit(timeout); |
124 | return process.WaitForExit(timeout); |