SELECT Query on Management Object

By using the "SELECT" query on Management Object
we can get Win32_PrintJob

Namespace part


using System;
using System.Management;


Coding part

public class MyClass {
public static void Main() {
string MyQuery = "SELECT * FROM Win32_PrintJob";
using (ManagementObjectSearcher MyManagementObjectSearcher = new ManagementObjectSearcher(MyQuery)) {
using (ManagementObjectCollection MyManagementObjectCollection = MyManagementObjectSearcher.Get()) {
foreach (ManagementObject MyManagementObject in MyManagementObjectCollection) {
Console.WriteLine(MyManagementObject["JobID"]);
}
}
}
}
}



Code Explanation

1. use the ManagementObjectSearcher for SELECT query
2. use the ManagementObjectCollection
3. By using the foreach we can get Jobid

By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: