public static void Create(string path, bool elevated) { if (Directory.Exists(path)) { throw new AlreadyExistsException(); } try { Directory.CreateDirectory(path); } catch (UnauthorizedAccessException) { if (elevated || !ElevatedOperation.CreateFolder(path)) { throw; } } }
public static void StopServices(string[] services) { if (!AdminRights.IsAdmin()) { ElevatedOperation.StopServices(services); } else { foreach (var service in services) { try { var controller = new ServiceController(service); controller.Stop(); } catch { } } } }