Hallo Merlin, schau mal hier vielleicht hilft dir das was ??
Ist aus einem Forum hatte ich mir irgendwann mal kopiert .
Vielleicht ein Ansatz
Option Explicit
' zunächst die benötigten API-Deklarationen
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(ByRef lpVersionInformation As OSVERSIONINFO) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
' -----------------------------------------------------
' Standarddrucker-Wechsel unter Win2k/XP
' -----------------------------------------------------
Private Declare Function SetPrinterDef Lib "winspool.drv" _
Alias "SetDefaultPrinterA" ( _
ByVal lpPrinter As String) As Long
' -----------------------------------------------------
' Standarddrucker-Wechsel unter Win9x
' -----------------------------------------------------
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" ( _
ByVal pPrinterName As String, _
phPrinter As Long, _
pDefault As PRINTER_DEFAULTS) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" ( _
ByVal hPrinter As Long) As Long
Private Declare Function GetPrinter Lib "winspool.drv" _
Alias "GetPrinterA" ( _
ByVal hPrinter As Long, _
ByVal Level As Long, _
pPrinter As Any, _
ByVal cbBuf As Long, _
pcbNeeded As Long) As Long
Private Declare Function SetPrinter Lib "winspool.drv" _
Alias "SetPrinterA" ( _
ByVal hPrinter As Long, _
ByVal Level As Long, _
pPrinter As Any, _
ByVal Command As Long) As Long
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As DEVMODE
DesiredAccess As Long
End Type
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PRINTER_ATTRIBUTE_DEFAULT = &H4
Private Const PRINTER_ACCESS_ADMINISTER = &H4
Private Const PRINTER_ACCESS_USE = &H8
Private Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)
' -----------------------------------------------------
' Standarddrucker-Wechsel unter WinNT4
' -----------------------------------------------------
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" ( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" ( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
lpData As Any, _
lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" ( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
lpData As Any, _
ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_WININICHANGE = &H1A
in dem Bereich jetzt must du einen Druckernamen festlegen:
' Standarddrucker-Wechsel
Public Function SetPrinterDefault(ByVal sPrinter As String) As Boolean
Dim OSVersion As OSVERSIONINFO
Dim nResult As Long
Dim hKey As Long
Dim hPrinter As Long
Dim nInfo() As Long
Dim udtPrinter As PRINTER_DEFAULTS
' Welches Betriebssystem wird verwendet?
With OSVersion
.dwOSVersionInfoSize = Len(OSVersion)
GetVersionEx OSVersion
If (.dwPlatformID = VER_PLATFORM_WIN32_NT) And _
(.dwMajorVersion > 4) Then
' Windows 2000 / XP
nResult = SetPrinterDef(sPrinter)
SetPrinterDefault = (nResult <> 0)
ElseIf (.dwPlatformID = VER_PLATFORM_WIN32_NT) And _
(.dwMajorVersion = 4) Then
' Windows NT 4
nResult = RegOpenKey(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows NT\CurrentVersion\Windows", hKey)
If nResult = 0 Then
If RegSetValueEx(hKey, "Device", 0, REG_SZ, _
sPrinter, Len(sPrinter)) = 0 Then
SetPrinterDefault = True
' System über Änderung benachrichtigen
SendMessage HWND_BROADCAST, WM_WININICHANGE, 0, 0
End If
RegCloseKey hKey
End If
Else
' Windows 9x
With udtPrinter
.DesiredAccess = PRINTER_ALL_ACCESS
End With
If OpenPrinter(sPrinter, hPrinter, udtPrinter) <> 0 Then
GetPrinter hPrinter, 5, ByVal 0&, 0&, nResult
ReDim nInfo(nResult \ 4)
GetPrinter hPrinter, 5, nInfo(0), nResult, nResult
nInfo(2) = nInfo(2) Or PRINTER_ATTRIBUTE_DEFAULT
If SetPrinter(hPrinter, 5, nInfo(0), 0&) <> 0 Then
SetPrinterDefault = True
End If
ClosePrinter hPrinter
End If
End If
End With
End Function
Gruß
Thomas
Ich bin ein Newbie . Aber jeder hat mal angefangen. Gruß & Dank Thomas
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!