wasSharpNET – Blame information for rev 16

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 {
16 office 15 private string domain;
16 private string URL;
9 office 17  
18 private readonly Regex URLReservationRegex;
16 office 19 private string username;
20 private int timeout;
9 office 21  
16 office 22 public URLACL(string URL, string username, string domain, int timeout)
9 office 23 {
24 this.URL = URL;
25 this.username = username;
26 this.domain = domain;
16 office 27 this.timeout = timeout;
9 office 28  
29 URLReservationRegex =
30 new Regex(
31 string.Format(@"{0}.*{1}", Regex.Escape(URL),
32 Regex.Escape(string.Format(@"{0}\{1}", domain, username))),
33 RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
34 RegexOptions.Compiled);
35 }
36  
37 public bool isReserved
38 {
39 get
40 {
41 var netSHOutput = new StringBuilder();
42 var checkProcess = new System.Diagnostics.Process();
43 checkProcess.StartInfo = new ProcessStartInfo("netsh", @"http show urlacl")
44 {
45 RedirectStandardOutput = true,
46 CreateNoWindow = true,
47 WindowStyle = ProcessWindowStyle.Hidden,
48 UseShellExecute = false
49 };
50  
51 checkProcess.OutputDataReceived += (sender, output) =>
52 {
53 if (output?.Data != null)
54 {
55 netSHOutput.Append(output.Data);
56 }
57 };
58  
59 checkProcess.Start();
60 checkProcess.BeginOutputReadLine();
16 office 61 checkProcess.WaitForExit(60000);
9 office 62  
63 return URLReservationRegex.IsMatch(netSHOutput.ToString());
64 }
65 }
66  
67 public void Reserve()
68 {
69 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
70 string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username))
71 {
72 Verb = @"runas",
73 CreateNoWindow = true,
74 WindowStyle = ProcessWindowStyle.Hidden,
16 office 75 UseShellExecute = false
76 }).WaitForExit(timeout);
9 office 77 }
78  
79 public void Release()
80 {
81 System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
82 string.Format(@"http del urlacl url={0}", URL))
83 {
84 Verb = @"runas",
85 CreateNoWindow = true,
86 WindowStyle = ProcessWindowStyle.Hidden,
16 office 87 UseShellExecute = false
88 }).WaitForExit(timeout);
9 office 89 }
90 }
11 office 91 }