Changing printer to adobe

Hi!

I try to change the printer to Adobe, print a document in pdf and replace the printer to the old one. I put my script in a bottom. when i clic the printer change to adobe, the document print on the old printer and the printer rechange on the old printer. I try to stop the script after it change to adobe and the printer was not changed, but when i close notes et reopen, the printer is changed to adobe. Why the printer change don’t change on my script. This is the code:

Declare Function GetProfileString Lib “kernel32.dll” 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.dll” Alias “WriteProfileStringA” ( _

Byval lpszSection As String, _

Byval lpszKeyName As String, _

Byval lpszString As String ) As Long

Declare Function SendMessage Lib “user32.dll” Alias “SendMessageA” ( _

Byval hwnd As Long, _

Byval wMsg As Long, _

Byval wParam As Long, _

lparam As Long ) As Long

Declare Sub SleepWin Lib “Kernel32.dll” Alias “Sleep” (Byval Milliseconds As Long)

Sub Click(Source As Button)

Const ok_info = 64

Const ok_excl = 48

Const yesno_excl = 52

Const ok_stop = 16

'Set default printer to be Adobe Writer

Dim szPrinter As String

szPrinter = "Adobe PDF"

'szPrinter = "\\CCD_MTL\Orlando.IMPRIMANTES.info"



'On Error Goto ErrorHandler



Const HWND_BROADCAST = &HFFFF

Const WM_WININICHANGE = &H1A

Const WM_SETTINGCHANGE = &H1A



Dim rc As Long

Dim slength As Long

Dim SendCommand As String

Dim oldprinter As String

Dim t As Long

Dim buffer As Variant

buffer = Space(1024)

Dim buflen As Long

buflen = Len(buffer)



rc = GetProfileString( "Devices", szPrinter, "", buffer, buflen )

Dim drivername As String

Dim printerport As String

t = Instr(buffer, ",")

If t > 0 Then 

	drivername = Left(buffer, t - 1 )

	k = Instr(t + 1, buffer, "," )

	If k > 0 Then

		printerport = Mid( buffer, t + 1, k - t - 1 )

	End If

Else

	Messagebox "You do not have the correct printer driver installed for this function. If the Adobe Acrobat PDFWriter Printer driver has been installed, please rename it to Acrobat PDFWriter."

	Exit Sub

End If

buffer = String(128, 0)

slength = GetProfileString("Windows", "Device", "(error)", buffer, 128)

OldPrinter = Left(buffer, slength) ' extract the returned string from the buffer

If OldPrinter = "(error)" Then

	Print "Could not read information from WIN.INI."

Else 

	Print "Original Printer: " & OldPrinter

End If

buffer = Space(1024)

buflen = Len(buffer)



rc = GetProfileString( "PrinterPorts", szPrinter, "", buffer, buflen )



i = Instr(buffer, ",")

If i > 0 Then 

	drivername = Left(buffer, i - 1 )

	k = Instr( i + 1, buffer, "," )

	If k > 0 Then

		printerport = Mid( buffer, i + 1, k - i - 1 )

	End If 

End If

Dim newprinter As String

newprinter = szPrinter & "," & drivername & "," & printerport

rc = WriteProfileString( "windows", "Device", NewPrinter)

rc = SendMessage( HWND_BROADCAST, WM_SETTINGCHANGE,0,0)

Call SleepWin(3000)

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’

Dim ws As New notesuiworkspace

Dim uiview As NotesUIView

pageseparator = 1

Set uiview = ws.Currentview

'Call uiview.Print( 1,,,,, "Demande+historique",,, )

'Call uiview.Print

'change default printer back

rc = WriteProfileString( "windows", "Device", OldPrinter)

rc = SendMessage( HWND_BROADCAST, WM_SETTINGCHANGE,0,0)

Call SleepWin(3000)

buffer = String(128, 0)

slength = GetProfileString("Windows", "Device", "(error)", buffer, 128)

NewPrinter = Left(buffer, slength) ' extract the returned string from the buffer

If NewPrinter = "(error)" Then

	Print "Could not read information from WIN.INI."

Else

	If NewPrinter = OldPrinter Then

		Print "Original Printer: " & OldPrinter

	Else

		While NewPrinter <> OldPrinter

			rc = WriteProfileString( "windows", "Device", OldPrinter)

			rc = SendMessage( HWND_BROADCAST, WM_SETTINGCHANGE,0,0)

			Call SleepWin(3000)

			buffer = String(128, 0)

			slength = GetProfileString("Windows", "Device", "(error)", buffer, 128)

			NewPrinter = Left(buffer, slength) ' extract the returned string from the buffer

		Wend

	End If

End If

End Sub

Estelle

Subject: Notes does not support the dynamic printer change

I have tried for years to get something like this to work, but never had success. I am using R8 now and I have not tried. I did a little test, with Notes open, change the default printer (via OS), check and see if Notes picked up on the change (NO!). Sorry I cannot be of more help. Eventually we just prompted users to select the PDF printer on the print dialog.