none
print count all client on DC RRS feed

  • Question

  • Printed count cliens on DC  analysis and reports.

    First step: log on script event 307 enable and copy evtx file repostory folder.

    Second step: C# read logs send MS SQL.

    Third step:  MVC Core  view and report.

    BUT :below has printer id instead of printer name. How do I find the printer name?

    Why do some computers have a printer name while some computers have a printer id? How do we fix this?


    hasan


    Monday, September 9, 2019 2:54 PM

Answers

  • Thank you for answer. Event id 842 match print id and name .Maybe it might be useful to someone else:

     private List<EventRecord> Read307(string path)
            {
                var records=new List<EventRecord>();
                using (var reader = new EventLogReader(path, PathType.FilePath))
                {
                    EventRecord record;
                    while ((record = reader.ReadEvent()) != null)
                    {
                        if (record.Id==307)
                        {
                            records.Add(record);
                        }
                    }
                }
                return records;
            }
            private List<EventRecord> Read842(string path)
            {
                var records = new List<EventRecord>();
                using (var reader = new EventLogReader(path, PathType.FilePath))
                {
                    EventRecord record;
                    while ((record = reader.ReadEvent()) != null)
                    {
                        if (record.Id == 842)
                        {
                            records.Add(record);
                        }
                    }
                }
                return records;
            }
    
            public List<info> ReadInfos(string path)
            {
                var infos = new List<info>();
                var records = Read307(path);
                var resords842 =Read842(path);
                var result = records.GroupBy(g => g.Properties[4].Value).Select(s =>
                    new { count = s.Sum(u => Convert.ToInt32(u.Properties[7].Value)), name = s.Key });
                var idg = resords842.GroupBy(g => g.Properties[2].Value)
                    .Select(s => new { name = s.Select(i => i.Properties[3].Value).FirstOrDefault(), s.Key });
                foreach (var idName in idg)
                {
                    var name = idName.name.ToString();
                    if (idName.Key.ToString().Contains('\\'))
                    {
                        var id = idName.Key.ToString().Split('\\')[3];
                        var destination = idName.Key.ToString().Split('\\')[2].Split('|')[1];
                        foreach (var r in result)
                        {
                            if (r.name.ToString() == id)
                            {
                                infos.Add(new info { Count = r.count, PrinterName = name, Source = destination });
                            }
                        }
                    }
                    else
                    {
                        result.ToList().ForEach(f=>infos.Add(new info{Count = f.count,PrinterName = f.name.ToString(),Source = ""}));
                    }
    
                }
                return infos;
            }


    hasan

    Tuesday, September 10, 2019 2:36 PM

All replies

  • Hi Hasan ŞAHİN,

    Thank you for posting here.

    According to your description, you want to get printer name.

    You could try the following code to get it.   

    Code:

               foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                {
                    MessageBox.Show(printer);
                }

    Hope my solution could be helpful.

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Tuesday, September 10, 2019 5:54 AM
    Moderator
  • Thank you for answer. Event id 842 match print id and name .Maybe it might be useful to someone else:

     private List<EventRecord> Read307(string path)
            {
                var records=new List<EventRecord>();
                using (var reader = new EventLogReader(path, PathType.FilePath))
                {
                    EventRecord record;
                    while ((record = reader.ReadEvent()) != null)
                    {
                        if (record.Id==307)
                        {
                            records.Add(record);
                        }
                    }
                }
                return records;
            }
            private List<EventRecord> Read842(string path)
            {
                var records = new List<EventRecord>();
                using (var reader = new EventLogReader(path, PathType.FilePath))
                {
                    EventRecord record;
                    while ((record = reader.ReadEvent()) != null)
                    {
                        if (record.Id == 842)
                        {
                            records.Add(record);
                        }
                    }
                }
                return records;
            }
    
            public List<info> ReadInfos(string path)
            {
                var infos = new List<info>();
                var records = Read307(path);
                var resords842 =Read842(path);
                var result = records.GroupBy(g => g.Properties[4].Value).Select(s =>
                    new { count = s.Sum(u => Convert.ToInt32(u.Properties[7].Value)), name = s.Key });
                var idg = resords842.GroupBy(g => g.Properties[2].Value)
                    .Select(s => new { name = s.Select(i => i.Properties[3].Value).FirstOrDefault(), s.Key });
                foreach (var idName in idg)
                {
                    var name = idName.name.ToString();
                    if (idName.Key.ToString().Contains('\\'))
                    {
                        var id = idName.Key.ToString().Split('\\')[3];
                        var destination = idName.Key.ToString().Split('\\')[2].Split('|')[1];
                        foreach (var r in result)
                        {
                            if (r.name.ToString() == id)
                            {
                                infos.Add(new info { Count = r.count, PrinterName = name, Source = destination });
                            }
                        }
                    }
                    else
                    {
                        result.ToList().ForEach(f=>infos.Add(new info{Count = f.count,PrinterName = f.name.ToString(),Source = ""}));
                    }
    
                }
                return infos;
            }


    hasan

    Tuesday, September 10, 2019 2:36 PM
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 9:03 AM
    Moderator