wasSharpNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 20  →  ?path2? @ 19
/Platform/Windows/Commands/NetSH/URLACL.cs
@@ -4,12 +4,9 @@
// 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
{
@@ -31,7 +28,8 @@
 
URLReservationRegex =
new Regex(
$@"{Regex.Escape(URL)}.*{Regex.Escape(string.Format(@"{0}\{1}", domain, username))}",
string.Format(@"{0}.*{1}", Regex.Escape(URL),
Regex.Escape(string.Format(@"{0}\{1}", domain, username))),
RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
RegexOptions.Compiled);
}
@@ -66,62 +64,28 @@
}
}
 
public bool Reserve()
public void Reserve()
{
System.Diagnostics.Process process = null;
try
System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
string.Format(@"http add urlacl url={0} user={1}\{2}", URL, domain, username))
{
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);
Verb = @"runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}).WaitForExit(timeout);
}
 
public bool Release()
public void Release()
{
System.Diagnostics.Process process = null;
try
System.Diagnostics.Process.Start(new ProcessStartInfo("netsh",
string.Format(@"http del urlacl url={0}", URL))
{
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);
Verb = @"runas",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}).WaitForExit(timeout);
}
}
}