Knowledge Base

How To Access ADSI PrintJob, Session, and Resource Objects

Article ID: 201033

Article Last Modified on 10/9/2006


APPLIES TO


This article was previously published under Q201033

SUMMARY

ADSI PrintJob, session, and resource objects are dynamic and are not in any ADs container. You enumerate and access them through collections exposed by other ADs objects. You cannot access dynamic objects using GetObject with an ADsPath.

MORE INFORMATION

PrintJobs are enumerated through the IADsPrintQueueOperations object's PrintJobs collection. You can get a reference to an IADsPrintQueueOperations by calling GetObject with an ADsPath that names a printer.

Sessions and resources are enumerated through the IADsFileServiceOperations object's Sessions and Resources collections. You can get a reference to an IADsFileServiceOperations object by calling GetObject with an ADsPath that specifies the LanManServer service of a computer.

The following code illustrates how to enumerate and access these dynamic objects. Note that each enumeration of the collection gives a new set of object references that reflect the current state of the collections.
Option Explicit
Sub main()

   Dim objFSOps As IADsFileServiceOperations
   Dim objResource As IADsResource
   Dim objSession As IADsSession

   Dim objPQOps As IADsPrintQueueOperations
   Dim objPrintJob As IADsPrintJob

   ' Replace domain, server, and printer below with actual domain, server,
   ' and printer names.
   Set objPQOps = GetObject("WinNT://domain/server/printer")

   For Each objPrintJob In objPQOps.PrintJobs
      Debug.Print objPrintJob.Name
   Next objPrintJob

   ' Replace domain and server below with actual domain and server names.
   Set objFSOps = GetObject("WinNT://domain/server/lanmanserver")

   For Each objSession In objFSOps.Sessions
      Debug.Print objSession.Name
   Next objSession

   For Each objResource In objFSOps.Resources
      Debug.Print objResource.Name
   Next objResource

End Sub
				

REFERENCES

For additional information, please see the following Web site:

Keywords: kbdswmanage2003swept kbapi kbhowto KB201033