示例#1
0
        /// <summary>
        ///     Returns true if the instance already exists for this category and machine specified.
        /// </summary>
        public static bool InstanceExists(string instanceName, string categoryName, string machineName)
        {
            if (instanceName == null)
            {
                throw new ArgumentNullException(nameof(instanceName));
            }

            if (categoryName == null)
            {
                throw new ArgumentNullException(nameof(categoryName));
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);

            return(category.InstanceExists(instanceName));
        }
        /// <devdoc>
        ///     Returns true if the category is registered in the machine.
        /// </devdoc>
        public static bool Exists(string categoryName, string machineName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "categoryName", categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, machineName, categoryName);

            permission.Demand();

            if (PerformanceCounterLib.IsCustomCategory(machineName, categoryName))
            {
                return(true);
            }

            return(PerformanceCounterLib.CategoryExists(machineName, categoryName));
        }
示例#3
0
        /// <summary>
        ///     Returns true if the counter is registered for this category on a particular machine.
        /// </summary>
        public static bool CounterExists(string counterName, string categoryName, string machineName)
        {
            if (counterName == null)
            {
                throw new ArgumentNullException(nameof(counterName));
            }

            if (categoryName == null)
            {
                throw new ArgumentNullException(nameof(categoryName));
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, machineName, categoryName);

            permission.Demand();

            return(PerformanceCounterLib.CounterExists(machineName, categoryName, counterName));
        }
示例#4
0
        private static void DeleteCategory(string categoryName, string machineName)
        {
            CheckValidCategory(categoryName);

            if (machineName != "." && String.Compare(machineName, PerformanceCounterLib.ComputerName, true, CultureInfo.InvariantCulture) != 0)
            {
                throw new NotSupportedException(SR.GetString(SR.RemoteCounterAdmin));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Administer, machineName, categoryName);

            permission.Demand();

            SharedUtils.CheckNtEnvironment();

            Mutex mutex = SharedUtils.EnterMutex(perfMutexName);

            try {
                if (!PerformanceCounterLib.IsCustomCategory(machineName, categoryName))
                {
                    throw new InvalidOperationException(SR.GetString(SR.CantDeleteCategory));
                }

                PerformanceCounterLib.UnregisterCategory(machineName, categoryName);
            }
            finally {
                mutex.ReleaseMutex();
                mutex.Close();
            }
        }
 public EventLogPermissionEntry(EventLogPermissionAccess permissionAccess, string machineName)
 {
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "MachineName", machineName }));
     }
     this.permissionAccess = permissionAccess;
     this.machineName      = machineName;
 }
 private static bool SourceExists(string source, string machineName, bool wantToCreate)
 {
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
     }
     new EventLogPermission(EventLogPermissionAccess.Write, machineName).Demand();
     using (RegistryKey key = FindSourceRegistration(source, machineName, true, wantToCreate))
     {
         return(key != null);
     }
 }
 public static PerformanceCounterCategory[] GetCategories(string machineName)
 {
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
     }
     new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Browse, machineName, "*").Demand();
     string[] categories = PerformanceCounterLib.GetCategories(machineName);
     PerformanceCounterCategory[] categoryArray = new PerformanceCounterCategory[categories.Length];
     for (int i = 0; i < categoryArray.Length; i++)
     {
         categoryArray[i] = new PerformanceCounterCategory(categories[i], machineName);
     }
     return(categoryArray);
 }
示例#8
0
 public MessageQueuePermissionEntry(MessageQueuePermissionAccess permissionAccess, string machineName, string label, string category)
 {
     if (((machineName == null) && (label == null)) && (category == null))
     {
         throw new ArgumentNullException("machineName");
     }
     if ((machineName != null) && !SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("InvalidParameter", new object[] { "MachineName", machineName }));
     }
     this.permissionAccess = permissionAccess;
     this.machineName      = machineName;
     this.label            = label;
     this.category         = category;
 }
示例#9
0
        /// <summary>
        ///     Returns an array of performance counter categories for a particular machine.
        /// </summary>
        public static PerformanceCounterCategory[] GetCategories(string machineName)
        {
            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            string[] categoryNames = PerformanceCounterLib.GetCategories(machineName);
            PerformanceCounterCategory[] categories = new PerformanceCounterCategory[categoryNames.Length];
            for (int index = 0; index < categories.Length; index++)
            {
                categories[index] = new PerformanceCounterCategory(categoryNames[index], machineName);
            }

            return(categories);
        }
示例#10
0
        /// <include file='doc\PerformanceCounterPermissionEntry.uex' path='docs/doc[@for="PerformanceCounterPermissionEntry.PerformanceCounterPermissionEntry"]/*' />
        public PerformanceCounterPermissionEntry(PerformanceCounterPermissionAccess permissionAccess, string machineName, string categoryName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "MachineName", machineName));
            }

            this.permissionAccess = permissionAccess;
            this.machineName      = machineName;
            this.categoryName     = categoryName;
        }
 public static bool Exists(string categoryName, string machineName)
 {
     if (categoryName == null)
     {
         throw new ArgumentNullException("categoryName");
     }
     if (categoryName.Length == 0)
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "categoryName", categoryName }));
     }
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
     }
     new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Browse, machineName, categoryName).Demand();
     return(PerformanceCounterLib.IsCustomCategory(machineName, categoryName) || PerformanceCounterLib.CategoryExists(machineName, categoryName));
 }
        /// <summary>
        ///     Creates a PerformanceCounterCategory object for given category.
        ///     Uses the given machine name.
        /// </summary>
        public PerformanceCounterCategory(string categoryName, string machineName)
        {
            ArgumentNullException.ThrowIfNull(categoryName);

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            _categoryName = categoryName;
            _machineName  = machineName;
        }
        /// <summary>
        ///     Returns true if the counter is registered for this category on a particular machine.
        /// </summary>
        public static bool CounterExists(string counterName, string categoryName, string machineName)
        {
            ArgumentNullException.ThrowIfNull(counterName);
            ArgumentNullException.ThrowIfNull(categoryName);

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            return(PerformanceCounterLib.CounterExists(machineName, categoryName, counterName));
        }
        /// <include file='..\..\doc\MessageQueuePermissionEntry.uex' path='docs/doc[@for="MessageQueuePermissionEntry.MessageQueuePermissionEntry1"]/*' />
        public MessageQueuePermissionEntry(MessageQueuePermissionAccess permissionAccess, string machineName, string label, string category)
        {
            if (machineName == null && label == null && category == null)
            {
                throw new ArgumentNullException(nameof(machineName));
            }

            if (machineName != null && !SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "MachineName", machineName));
            }

            this.permissionAccess = permissionAccess;
            this.machineName      = machineName;
            this.label            = label;
            this.category         = category;
        }
示例#15
0
        /// <summary>
        /// Creates an array of frames from a string expression. The expression must be similar to the following format:
        /// "0,3,7-11,2,5"
        /// Whitespace is permitted, and commas are optional.
        /// <param name="input">A string formatted as above, describing the frames to generate.</param>
        /// </summary>
        public static int[] ParseFrames(string input)
        {
            // Make sure the pattern matches, and alert the user if it doesn't
            var parse = SyntaxCheck.Match(input);

            if (!parse.Success)
            {
                throw new Exception(string.Format("Invalid format: {0}", input));
            }

            // Get all numbers/ranges in the input string.
            var frames = new List <int>();

            foreach (Match match in GetMatches.Matches(input))
            {
                var range = GetRange.Match(match.Value);
                if (range.Success)
                {
                    int from = int.Parse(range.Groups[1].Value);
                    int to   = int.Parse(range.Groups[2].Value);

                    // Support ascending and descending ranges
                    if (from < to)
                    {
                        while (from <= to)
                        {
                            frames.Add(from++);
                        }
                    }
                    else
                    {
                        while (from >= to)
                        {
                            frames.Add(from--);
                        }
                    }
                }
                else
                {
                    frames.Add(int.Parse(match.Value));
                }
            }

            return(frames.ToArray());
        }
示例#16
0
 internal ServiceController(string machineName, System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS_PROCESS status)
 {
     this.machineName = ".";
     this.name        = "";
     this.displayName = "";
     this.eitherName  = "";
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
     }
     this.machineName      = machineName;
     this.name             = status.serviceName;
     this.displayName      = status.displayName;
     this.commandsAccepted = status.controlsAccepted;
     this.status           = (ServiceControllerStatus)status.currentState;
     this.type             = status.serviceType;
     this.statusGenerated  = true;
 }
 public PerformanceCounterCategory(string categoryName, string machineName)
 {
     if (categoryName == null)
     {
         throw new ArgumentNullException("categoryName");
     }
     if (categoryName.Length == 0)
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "categoryName", categoryName }));
     }
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
     }
     new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Browse, machineName, categoryName).Demand();
     this.categoryName = categoryName;
     this.machineName  = machineName;
 }
示例#18
0
 public ServiceController(string name, string machineName)
 {
     this.machineName = ".";
     this.name        = "";
     this.displayName = "";
     this.eitherName  = "";
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
     }
     if ((name == null) || (name.Length == 0))
     {
         throw new ArgumentException(Res.GetString("InvalidParameter", new object[] { "name", name }));
     }
     this.machineName = machineName;
     this.eitherName  = name;
     this.type        = 0x13f;
 }
示例#19
0
 public ServiceControllerPermissionEntry(ServiceControllerPermissionAccess permissionAccess, string machineName, string serviceName)
 {
     if (serviceName == null)
     {
         throw new ArgumentNullException("serviceName");
     }
     if (!ServiceController.ValidServiceName(serviceName))
     {
         object[] args = new object[] { serviceName, 80.ToString(CultureInfo.CurrentCulture) };
         throw new ArgumentException(Res.GetString("ServiceName", args));
     }
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
     }
     this.permissionAccess = permissionAccess;
     this.machineName      = machineName;
     this.serviceName      = serviceName;
 }
        public static bool Exists(string logName, string machineName)
        {
            bool flag;

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString("InvalidParameterFormat", new object[] { "machineName" }));
            }
            new EventLogPermission(EventLogPermissionAccess.Administer, machineName).Demand();
            if ((logName == null) || (logName.Length == 0))
            {
                return(false);
            }
            SharedUtils.CheckEnvironment();
            _UnsafeGetAssertPermSet().Assert();
            RegistryKey eventLogRegKey = null;
            RegistryKey key2           = null;

            try
            {
                eventLogRegKey = GetEventLogRegKey(machineName, false);
                if (eventLogRegKey == null)
                {
                    return(false);
                }
                key2 = eventLogRegKey.OpenSubKey(logName, false);
                flag = key2 != null;
            }
            finally
            {
                if (eventLogRegKey != null)
                {
                    eventLogRegKey.Close();
                }
                if (key2 != null)
                {
                    key2.Close();
                }
                CodeAccessPermission.RevertAssert();
            }
            return(flag);
        }
示例#21
0
        /// <include file='doc\PerformanceCounterCategory.uex' path='docs/doc[@for="PerformanceCounterCategory.GetCounterInstances"]/*' />
        /// <devdoc>
        ///     Returns the instance names for a given category
        /// </devdoc>
        /// <internalonly/>
        internal static string[] GetCounterInstances(string categoryName, string machineName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "categoryName", categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Browse, machineName, categoryName);

            permission.Demand();

            CategorySample categorySample = PerformanceCounterLib.GetCategorySample(machineName, categoryName);

            try {
                if (categorySample.InstanceNameTable.Count == 0)
                {
                    throw new InvalidOperationException(SR.GetString(SR.NoInstanceInformation, categoryName));
                }

                string[] instanceNames = new string[categorySample.InstanceNameTable.Count];
                categorySample.InstanceNameTable.Keys.CopyTo(instanceNames, 0);
                if (instanceNames.Length == 1 && instanceNames[0].CompareTo(PerformanceCounterLib.SingleInstanceName) == 0)
                {
                    return(new string[0]);
                }

                return(instanceNames);
            }
            finally {
                categorySample.Dispose();
            }
        }
        /// <devdoc>
        ///     Returns an array of performance counter categories for a particular machine.
        /// </devdoc>
        public static PerformanceCounterCategory[] GetCategories(string machineName)
        {
            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, machineName, "*");

            permission.Demand();

            string[] categoryNames = PerformanceCounterLib.GetCategories(machineName);
            PerformanceCounterCategory[] categories = new PerformanceCounterCategory[categoryNames.Length];
            for (int index = 0; index < categories.Length; index++)
            {
                categories[index] = new PerformanceCounterCategory(categoryNames[index], machineName);
            }

            return(categories);
        }
示例#23
0
        private static ServiceController[] GetServicesOfType(string machineName, int serviceType)
        {
            ServiceController[] controllerArray;
            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(Res.GetString("BadMachineName", new object[] { machineName }));
            }
            new ServiceControllerPermission(ServiceControllerPermissionAccess.Browse, machineName, "*").Demand();
            CheckEnvironment();
            IntPtr zero         = IntPtr.Zero;
            IntPtr status       = IntPtr.Zero;
            int    resumeHandle = 0;

            try
            {
                int num;
                int num2;
                zero = GetDataBaseHandleWithEnumerateAccess(machineName);
                System.ServiceProcess.UnsafeNativeMethods.EnumServicesStatus(zero, serviceType, 3, IntPtr.Zero, 0, out num, out num2, ref resumeHandle);
                status = Marshal.AllocHGlobal((IntPtr)num);
                System.ServiceProcess.UnsafeNativeMethods.EnumServicesStatus(zero, serviceType, 3, status, num, out num, out num2, ref resumeHandle);
                int num4 = num2;
                controllerArray = new ServiceController[num4];
                for (int i = 0; i < num4; i++)
                {
                    IntPtr ptr = (IntPtr)(((long)status) + (i * Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS))));
                    System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS structure = new System.ServiceProcess.NativeMethods.ENUM_SERVICE_STATUS();
                    Marshal.PtrToStructure(ptr, structure);
                    controllerArray[i] = new ServiceController(machineName, structure);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(status);
                if (zero != IntPtr.Zero)
                {
                    SafeNativeMethods.CloseServiceHandle(zero);
                }
            }
            return(controllerArray);
        }
示例#24
0
        /// <include file='doc\ServiceControllerPermissionEntry.uex' path='docs/doc[@for="ServiceControllerPermissionEntry.ServiceControllerPermissionEntry1"]/*' />
        public ServiceControllerPermissionEntry(ServiceControllerPermissionAccess permissionAccess, string machineName, string serviceName)
        {
            if (serviceName == null)
            {
                throw new ArgumentNullException("serviceName");
            }

            if (!ServiceController.ValidServiceName(serviceName))
            {
                throw new ArgumentException(Res.GetString(Res.ServiceName, serviceName, ServiceBase.MaxNameLength.ToString()));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(Res.GetString(Res.BadMachineName, machineName));
            }

            this.permissionAccess = permissionAccess;
            this.machineName      = machineName;
            this.serviceName      = serviceName;
        }
        public static bool InstanceExists(string instanceName, string categoryName, string machineName)
        {
            if (instanceName == null)
            {
                throw new ArgumentNullException("instanceName");
            }
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }
            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "categoryName", categoryName }));
            }
            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
            }
            PerformanceCounterCategory category = new PerformanceCounterCategory(categoryName, machineName);

            return(category.InstanceExists(instanceName));
        }
 public PerformanceCounterPermissionEntry(PerformanceCounterPermissionAccess permissionAccess, string machineName, string categoryName)
 {
     if (categoryName == null)
     {
         throw new ArgumentNullException("categoryName");
     }
     if ((permissionAccess & ~PerformanceCounterPermissionAccess.Administer) != PerformanceCounterPermissionAccess.None)
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "permissionAccess", permissionAccess }));
     }
     if (machineName == null)
     {
         throw new ArgumentNullException("machineName");
     }
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "MachineName", machineName }));
     }
     this.permissionAccess = permissionAccess;
     this.machineName      = machineName;
     this.categoryName     = categoryName;
 }
示例#27
0
        /// <summary>
        ///     Returns true if the category is registered in the machine.
        /// </summary>
        public static bool Exists(string categoryName, string machineName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException(nameof(categoryName));
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            if (PerformanceCounterLib.IsCustomCategory(machineName, categoryName))
            {
                return(true);
            }

            return(PerformanceCounterLib.CategoryExists(machineName, categoryName));
        }
示例#28
0
        /// <summary>
        ///     Creates a PerformanceCounterCategory object for given category.
        ///     Uses the given machine name.
        /// </summary>
        public PerformanceCounterCategory(string categoryName, string machineName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException(nameof(categoryName));
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(categoryName), categoryName), nameof(categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName), nameof(machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, machineName, categoryName);

            permission.Demand();

            _categoryName = categoryName;
            _machineName  = machineName;
        }
        public static EventLog[] GetEventLogs(string machineName)
        {
            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
            }
            new EventLogPermission(EventLogPermissionAccess.Administer, machineName).Demand();
            SharedUtils.CheckEnvironment();
            string[] subKeyNames = new string[0];
            _UnsafeGetAssertPermSet().Assert();
            RegistryKey eventLogRegKey = null;

            try
            {
                eventLogRegKey = GetEventLogRegKey(machineName, false);
                if (eventLogRegKey == null)
                {
                    throw new InvalidOperationException(SR.GetString("RegKeyMissingShort", new object[] { @"SYSTEM\CurrentControlSet\Services\EventLog", machineName }));
                }
                subKeyNames = eventLogRegKey.GetSubKeyNames();
            }
            finally
            {
                if (eventLogRegKey != null)
                {
                    eventLogRegKey.Close();
                }
                CodeAccessPermission.RevertAssert();
            }
            EventLog[] logArray = new EventLog[subKeyNames.Length];
            for (int i = 0; i < subKeyNames.Length; i++)
            {
                logArray[i] = new EventLog(subKeyNames[i], machineName);
            }
            return(logArray);
        }
        /// <devdoc>
        ///     Creates a PerformanceCounterCategory object for given category.
        ///     Uses the given machine name.
        /// </devdoc>
        public PerformanceCounterCategory(string categoryName, string machineName)
        {
            if (categoryName == null)
            {
                throw new ArgumentNullException("categoryName");
            }

            if (categoryName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "categoryName", categoryName));
            }

            if (!SyntaxCheck.CheckMachineName(machineName))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));
            }

            PerformanceCounterPermission permission = new PerformanceCounterPermission(PerformanceCounterPermissionAccess.Read, machineName, categoryName);

            permission.Demand();

            this.categoryName = categoryName;
            this.machineName  = machineName;
        }