HOWTO: Access ADSI PrintJob, Session, and Resource Objects

ID: Q201033


The information in this article applies to:


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:

http://www.microsoft.com/windows/server/Deploy/directory/default.asp

Additional query words:


Keywords          : kbADSI kbAPI 
Version           : WINDOWS:4.0,5.0,6.0; winnt:2.0,4.0
Platform          : WINDOWS winnt 
Issue type        : kbhowto 

Last Reviewed: June 18, 1999