Exemplo n.º 1
0
        public override RuleInstanceInfo[] List()
        {
            List <RuleInstanceInfo> result = new List <RuleInstanceInfo>();

            NativeMethods.EnumWindowStationsDelegate childProc = new NativeMethods.EnumWindowStationsDelegate((windowStation, lParam) =>
            {
                GCHandle gch        = GCHandle.FromIntPtr(lParam);
                IList <string> list = gch.Target as List <string>;

                if (null == list)
                {
                    return(false);
                }

                list.Add(windowStation);

                return(true);
            });

            IList <string> workstationList = EnumWindowsStations(childProc);

            foreach (string workstation in workstationList)
            {
                result.Add(new RuleInstanceInfo()
                {
                    Name = workstation
                });
            }

            return(result.ToArray());
        }
Exemplo n.º 2
0
        private static IList <string> EnumWindowsStations(NativeMethods.EnumWindowStationsDelegate childProc)
        {
            IList <string> workstationList = new List <string>();
            GCHandle       gcHandle        = GCHandle.Alloc(workstationList);

            if (!NativeMethods.EnumWindowStations(childProc, GCHandle.ToIntPtr(gcHandle)))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return(workstationList);
        }
Exemplo n.º 3
0
        public override RuleInstanceInfo[] List()
        {
            List<RuleInstanceInfo> result = new List<RuleInstanceInfo>();

            NativeMethods.EnumWindowStationsDelegate childProc = new NativeMethods.EnumWindowStationsDelegate((windowStation, lParam) =>
            {
                GCHandle gch = GCHandle.FromIntPtr(lParam);
                IList<string> list = gch.Target as List<string>;

                if (null == list)
                {
                    return false;
                }

                list.Add(windowStation);

                return true;
            });

            IList<string> workstationList = EnumWindowsStations(childProc);

            foreach (string workstation in workstationList)
            {
                result.Add(new RuleInstanceInfo() { Name = workstation });
            }

            return result.ToArray();
        }