wasSharpNET – Blame information for rev 11

Subversion Repositories:
Rev:
Rev Author Line No. Line
9 office 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 using System.Diagnostics;
8 using System.Text;
9 using System.Text.RegularExpressions;
10  
11 namespace wasSharpNET.Platform.Windows.Commands.NetSH
12 {
13 public class URLACL
14 {
15 public string domain;
16 public string URL;
17  
18 private readonly Regex URLReservationRegex;
19 public string username;
20  
21 public URLACL(string URL, string username, string domain)
22 {
23 this.URL = URL;
24 this.username = username;
25 this.domain = domain;
26  
27 URLReservationRegex =
28 new Regex(
29 string.Format(@"{0}.*{1}", Regex.Escape(URL),
30 Regex.Escape(string.Format(@"{0}\{1}", domain, username))),
31 RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
32 RegexOptions.Compiled);
33 }
34  
35 public bool isReserved
36 {
37 get
38 {
39 var netSHOutput = new StringBuilder();
40 var checkProcess = new System.Diagnostics.Process();
41 checkProcess.StartInfo = new ProcessStartInfo("netsh", @"http show urlacl")
42 {
43 RedirectStandardOutput = true,
44 CreateNoWindow = true,
45 WindowStyle = ProcessWindowStyle.Hidden,
46 UseShellExecute = false
47 };
48  
49 checkProcess.OutputDataReceived += (sender, output) =>
50 {
51 if (output?.Data != null)
52 {
53 netSHOutput.Append(output.Data);
54 }
55 };
56  
57 checkProcess.Start();
58 checkProcess.BeginOutputReadLine();
59 checkProcess.WaitForExit();
60  
61 return URLReservationRegex.IsMatch(netSHOutput.ToString());
62 }
63 }
64  
65 public void Reserve()
66 {
67 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
68 string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username))
69 {
70 Verb = @"runas",
71 CreateNoWindow = true,
72 WindowStyle = ProcessWindowStyle.Hidden,
73 UseShellExecute = true
74 }).WaitForExit();
75 }
76  
77 public void Release()
78 {
79 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
80 string.Format(@"http del urlacl url={0}", URL))
81 {
82 Verb = @"runas",
83 CreateNoWindow = true,
84 WindowStyle = ProcessWindowStyle.Hidden,
85 UseShellExecute = true
86 }).WaitForExit();
87 }
88 }
11 office 89 }