Hallo,
ich habe die beiden Teile einmal zusammengefügt - und herausgekommen ist ein kleiner AGent - gestartet aus der Agentenliste mit Ziel KEINES - den man dann in jeder Notes-Applikation einbauen kann, um damit den Defaultprinter zu ermitteln bzw. umzuswitchen:
(Options)
Option Public
Option Declare
(Declarations)
Dim WshNetwork As Variant
Dim wshShell As Variant
Dim WshPrinters As Variant
Dim pArray() As String
Dim iRetValue As Long
Dim DefaultPrinter As String
Dim pCount As Integer
Dim printerAvailable As Boolean
Dim n As Integer
Sub Initialize
Dim ws As New NotesUIWorkspace
' Dim pcount As Integer
' Dim n As Integer
Dim response As Variant
Dim sDefault As String
Set WshNetwork = CreateObject("WScript.Network")
Set WshPrinters = WshNetwork.EnumPrinterConnections()
'count the connected printers
pCount% = 0
For n = 1 To WshPrinters.Count() Step 2
If wshPrinters(n) <> "" Then pCount%=pCount%+1
Next
If pcount%=0 Then Exit Sub ' no Printers found
'collect the names of the connected printers
Redim pArray(pCount%-1) As String
pCount% = 0
For n = 1 To WshPrinters.Count() Step 2
If wshPrinters(n) <> "" Then
pArray(pCount%) = wshPrinters(n)
pCount%=pCount%+1
End If
Next
' Determine the actual Default printer
Set wshShell = CreateObject("WScript.Shell")
sDefault = ""
On Error Resume Next
sDefault = wshShell.RegRead("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
sDefault = Left(sDefault ,Instr(sDefault, ",") - 1)
response = ws.Prompt (PROMPT_OKCANCELLIST, _
"Selection of defaultprinter", _
"Select the new defaultprinter. The actual Defaultprinter - if existant - is highlighted", _
sDefault, pArray)
If Isempty (response) Then Exit Sub ' If user presses CANCEL, then exit
WshNetwork.SetDefaultPrinter response
Set WshNetwork = Nothing
Set WshShell = Nothing
End Sub