wasSharpNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 26  →  ?path2? @ 27
/Platform/Windows/Commands/NetSH/URLACL.cs
@@ -14,11 +14,11 @@
public class URLACL
{
private readonly string domain;
private readonly int timeout;
private readonly string URL;
 
private readonly Regex URLReservationRegex;
private readonly string username;
private readonly int timeout;
 
public URLACL(string URL, string username, string domain, int timeout)
{
@@ -53,9 +53,7 @@
checkProcess.OutputDataReceived += (sender, output) =>
{
if (output?.Data != null)
{
netSHOutput.Append(output.Data);
}
};
 
checkProcess.Start();
@@ -84,9 +82,7 @@
{
// User cancelled the UAC elevation prompt.
if (ex.NativeErrorCode == 1223)
{
return false;
}
}
 
if (process == null)
@@ -113,9 +109,7 @@
{
// User cancelled the UAC elevation prompt.
if (ex.NativeErrorCode == 1223)
{
return false;
}
}
 
if (process == null)
@@ -124,4 +118,4 @@
return process.WaitForExit(timeout);
}
}
}
}
/Platform/Windows/Services/Utilities.cs
@@ -0,0 +1,46 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System;
using System.ServiceProcess;
 
namespace wasSharpNET.Platform.Windows.Services
{
public static class Utilities
{
/// <summary>
/// Start or stop a service.
/// </summary>
/// <param name="service">the name of service</param>
/// <param name="running">the requested service state</param>
/// <returns>true if the action could be performed</returns>
public static void SetServiceRunning(string service, bool running)
{
var s = new ServiceController(service);
 
// Do not make any change in case the service status matches the requested service status.
if (s.Status.Equals(ServiceControllerStatus.Running) && running)
return;
 
if (s.Status.Equals(ServiceControllerStatus.Stopped) && !running)
return;
 
switch (running)
{
case true:
s.Start();
break;
case false:
s.Stop();
break;
}
 
// Default Windows timespan of 30 seconds for service status result.
s.WaitForStatus(running ? ServiceControllerStatus.Running : ServiceControllerStatus.Stopped,
TimeSpan.FromSeconds(60));
}
}
}
/Platform/Windows/Utilities.cs
@@ -40,5 +40,13 @@
 
return true;
}
 
public static bool isWindows()
{
return Environment.OSVersion.Platform.Equals(PlatformID.Win32NT) ||
Environment.OSVersion.Platform.Equals(PlatformID.Win32S) ||
Environment.OSVersion.Platform.Equals(PlatformID.Win32Windows) ||
Environment.OSVersion.Platform.Equals(PlatformID.WinCE);
}
}
}