Subject: RE: How to select printer by using lotus script in R6.5
Actually there is a wayHere is code that I found some time ago and worked well for me
Declarations:
Const HWND_BROADCAST = &HFFFF&
Const WM_WININICHANGE = &H1A
Declare Function GetProfileString Lib “kernel32” Alias “GetProfileStringA” _
(Byval lpAppName As String, _
Byval lpKeyName As String, _
Byval lpDefault As String, _
Byval lpReturnedString As String, _
Byval nSize As Long) As Long
Declare Function WriteProfileString Lib “kernel32” Alias “WriteProfileStringA” _
(Byval lpszSection As String, _
Byval lpszKeyName As String, _
Byval lpszString As String) As Long
Declare Function SendNotifyMessage Lib “user32” Alias “SendNotifyMessageA” _
(Byval hwnd As Long, _
Byval msg As Long, _
Byval wParam As Long, _
lParam As Any) As Long
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Call SetDefPrinter("HP4200_Prod", "", "IP_10.0.4.59")
Call uidoc.Print( 1 )
End Sub
Sub SetDefPrinter(Byval PrinterName As String, Byval DriverName As String, Byval PrinterPort As String)
Dim DeviceLine As String
'rebuild a valid device line string
DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort
'Store the new printer information in the
'[WINDOWS] section of the WIN.INI file for
'the DEVICE= item
Call WriteProfileString("windows", "Device", DeviceLine)
'Cause all applications to reload the INI file
Call SendNotifyMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Byval "windows")
End Sub
Sub GetDriverAndPort(Byval Buffer As String, DriverName As String, PrinterPort As String)
Dim posDriver As Long
Dim posPort As Long
DriverName = ""
PrinterPort = ""
'The driver name is first in the string
'terminated by a comma
posDriver = Instr(Buffer, ",")
If posDriver > 0 Then
'Strip out the driver name
DriverName = Left(Buffer, posDriver - 1)
'The port name is the second entry after
'the driver name separated by commas.
posPort = Instr(posDriver + 1, Buffer, ",")
If posPort > 0 Then
'Strip out the port name
PrinterPort = Mid(Buffer, posDriver + 1, posPort - posDriver - 1)
End If
End If
End Sub
Function StripNulls(startstr As String) As String
'Take a string separated by chr$(0)
'and split off 1 item, shortening the
'string so next item is ready for removal.
Dim pos As Long
pos = Instr(startstr$, Chr$(0))
If pos Then
StripNulls = Mid$(startstr, 1, pos - 1)
startstr = Mid$(startstr, pos + 1, Len(startstr))
End If
End Function
Sub SetDefaultPrinterWinNT()
Dim Buffer As String
Dim DeviceName As String
Dim DriverName As String
Dim PrinterPort As String
Dim PrinterName As String
Dim r As Long
If List1.ListIndex > -1 Then
'Get the printer information for the currently selected
'printer in the list. The information is taken from the
'WIN.INI file.
Buffer = Space(1024)
PrinterName = List1.list(list1.ListIndex)
Call GetProfileString("PrinterPorts", PrinterName, "", Buffer, Len(Buffer))
'Parse the driver name and port name out of the buffer
GetDriverAndPort Buffer, DriverName, PrinterPort
If (Len(DriverName) > 0) And (Len(PrinterPort) > 0) Then
SetDefPrinter PrinterName, DriverName, PrinterPort
End If
End If
End Sub