wasSharpNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 16  →  ?path2? @ 20
/Platform/Windows/Commands/NetSH/URLACL.cs
@@ -4,9 +4,12 @@
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using Process = System.Diagnostics.Process;
 
namespace wasSharpNET.Platform.Windows.Commands.NetSH
{
@@ -28,8 +31,7 @@
 
URLReservationRegex =
new Regex(
string.Format(@"{0}.*{1}", Regex.Escape(URL),
Regex.Escape(string.Format(@"{0}\{1}", domain, username))),
$@"{Regex.Escape(URL)}.*{Regex.Escape(string.Format(@"{0}\{1}", domain, username))}",
RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
RegexOptions.Compiled);
}
@@ -64,28 +66,62 @@
}
}
 
public void Reserve()
public bool Reserve()
{
System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username))
System.Diagnostics.Process process = null;
try
{
Verb = @"runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}).WaitForExit(timeout);
process = System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
$@"http add urlacl url={URL} user={domain}\{username}")
{
Verb = @"runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true
});
}
catch (Win32Exception ex)
{
// User cancelled the UAC elevation prompt.
if (ex.NativeErrorCode == 1223)
{
return false;
}
}
 
if (process == null)
return false;
 
return process.WaitForExit(timeout);
}
 
public void Release()
public bool Release()
{
System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
string.Format(@"http del urlacl url={0}", URL))
System.Diagnostics.Process process = null;
try
{
Verb = @"runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}).WaitForExit(timeout);
process = System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
$@"http del urlacl url={URL}")
{
Verb = @"runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true
});
}
catch (Win32Exception ex)
{
// User cancelled the UAC elevation prompt.
if (ex.NativeErrorCode == 1223)
{
return false;
}
}
 
if (process == null)
return false;
 
return process.WaitForExit(timeout);
}
}
}