Subject: RE: Selecting a printer in a script
Ok, here’s the pieces I use to go to adobe writer and then back to the default printer. I’ll TRY and get all the pieces in here. I got them from some very wonderful person a few years ago, I just can’t remeber who! 
Ok, in the declarations of a script library I have:
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)
Const ok_info = 64
Const ok_excl = 48
Const yesno_excl = 52
Const ok_stop = 16
Then…in the script to change the printer:
'Set default printer to be Adobe Writer
Dim szPrinter As String
szPrinter = "Acrobat PDFWriter"
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)
'''''''''''''''''''''
I call Intelliprint after that and go through that whole thing, so I don’t know what you’ll have to do. After that’s finished, I change it back to the default printer:
'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
I hope this helps you!
Deb