Microsoft KB Archive/201033

{|
 * width="100%"|

HOWTO: Access ADSI PrintJob, Session, and Resource Objects

 * }

Q201033

-

The information in this article applies to:


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

-

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