How To Access ADSI PrintJob, Session, and Resource Objects (201033)



The information in this article applies to:

  • Microsoft Windows NT Server 4.0
  • Microsoft Windows NT Workstation 4.0
  • Microsoft Visual Basic Professional Edition for Windows 4.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 4.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Active Directory Service Interfaces 2.0
  • Microsoft Active Directory Service Interfaces 2.5

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
				

Modification Type:MajorLast Reviewed:10/9/2006
Keywords:kbDSWManage2003Swept kbAPI kbhowto KB201033