wasSharpNET – Blame information for rev 9

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  
62 return URLReservationRegex.IsMatch(netSHOutput.ToString());
63 }
64 }
65  
66 public void Reserve()
67 {
68 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
69 string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username))
70 {
71 Verb = @"runas",
72 CreateNoWindow = true,
73 WindowStyle = ProcessWindowStyle.Hidden,
74 UseShellExecute = true
75 }).WaitForExit();
76 }
77  
78 public void Release()
79 {
80 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
81 string.Format(@"http del urlacl url={0}", URL))
82 {
83 Verb = @"runas",
84 CreateNoWindow = true,
85 WindowStyle = ProcessWindowStyle.Hidden,
86 UseShellExecute = true
87 }).WaitForExit();
88 }
89 }
90 }