The usual methods for getting the printer names will give me all printers in
all active user sessions:
Public Sub DiscoverPrinters()
Dim strDefaultPrinter As String
Dim objPrinter As Object
For Each objPrinter In Printers
If objPrinter.DeviceName = Printer.DeviceName Then
strDefaultPrinter = objPrinter.DeviceName
End If
mcol_Printers.Add Item:=CStr(objPrinter.DeviceName),
Key:=CStr(objPrinter.DeviceName)
Next
End Sub
Any ideas on how to grab just the printers specific to the user?
***********************
Option Explicit
Private Declare Function WTSQuerySessionInformation Lib "wtsapi32" _
Alias "WTSQuerySessionInformationA" (ByVal hServer As Long, _
ByVal SessionID As Long, ByVal WTSInfoClass As Long, _
ByRef ppBuffer As Long, ByRef lLen As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Const WTS_CURRENT_SERVER_HANDLE As Long = 0
Private Const WTS_CURRENT_SESSION As Long = -1
Public Function GetTSSessionID() As Long
Dim sVal As String
Dim lVal As Long
Dim intVal As Integer
Dim lRet As Long
Dim lLen As Long
Dim lErr As Long
Dim I As Long
Dim sIP As String
Dim lBufferAddress As Long
lRet = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _
WTS_CURRENT_SESSION, _
4, _
lBufferAddress, _
lLen)
' copying the buffer to a VB string
If lLen > 0 Then
lVal = 0
CopyMemory lVal, ByVal lBufferAddress, lLen
GetTSSessionID = lVal
End If
If lRet = 0 Then
lErr = Err.LastDllError
GetTSSessionID = -1
End If
End Function
**********************************
In your DiscoverPrinters add
Dim strSession As String
Dim lngSession As Long
lngSession = GetTSSesssionID()
If lngSession > 0 Then strSession = "/Session " & lngSession
Then you test the devicename to see if it has a double underscore at the
beginning, if it has test to see if the devicename contains the strSession
value.
--
regards
Ian
*** inavlid email address - change country code to full country name
"Mkjo" <Mk...@discussions.microsoft.com> wrote in message
news:1791E414-7572-4773...@microsoft.com...
Thanks Ian.