Initial Release Batch Version
This commit is contained in:
commit
c1383fcd0c
26 changed files with 1783 additions and 0 deletions
3
Assets/UTAX/SWConfig.xml
Normal file
3
Assets/UTAX/SWConfig.xml
Normal file
File diff suppressed because one or more lines are too long
116
Assets/UTAX/Simple Utax SW Farbe.bat
Normal file
116
Assets/UTAX/Simple Utax SW Farbe.bat
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
@echo off
|
||||
:: Prüfe, ob Admin-Rechte vorhanden sind
|
||||
NET SESSION >nul 2>&1
|
||||
IF %ERRORLEVEL% NEQ 0 (
|
||||
echo Starte Skript mit Admin-Rechten ...
|
||||
powershell -Command "Start-Process cmd -ArgumentList '/c \"%~f0\"' -Verb RunAs"
|
||||
exit
|
||||
)
|
||||
|
||||
:: Druckermodell eingeben
|
||||
set /p PRINTER_MODEL="Bitte gib genau an, um welchen Drucker es sich handelt(z.b. P-5034I oder 2508ci): "
|
||||
|
||||
:: Druckertreiber mit Modell + KX setzen
|
||||
set DRIVER_NAME="%PRINTER_MODEL% KX"
|
||||
|
||||
:: IP-Adresse eingeben
|
||||
set /p PRINTER_IP="Gib die IP-Adresse des Druckers ein: "
|
||||
|
||||
:: Druckernamen eingeben
|
||||
set /p PRINTER_NAME="Gib den Namen des Druckers ein (ohne SW/Farbe): "
|
||||
|
||||
:: Standarddrucker-Liste setzen (SW und Farbe)
|
||||
set PRINTER_LIST="%PRINTER_NAME% (SW)" "%PRINTER_NAME% (Farbe)"
|
||||
|
||||
|
||||
:default_path
|
||||
:: Nutzt automatisch den Pfad der Batch-Datei
|
||||
set BASE_PATH=%~dp0
|
||||
set DRIVER_PATH=%BASE_PATH%Utax-treiber
|
||||
set DELETE_DRIVER_PATH=1
|
||||
echo Verwende automatisch den Treiberordner: %DRIVER_PATH%
|
||||
|
||||
:: Pruefe, ob der Treiberordner existiert
|
||||
if not exist "%DRIVER_PATH%" (
|
||||
echo Treiber nicht gefunden! Lade ihn herunter...
|
||||
|
||||
:: Treiber von Utax herunterladen
|
||||
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('https://www.dropbox.com/scl/fi/smk1cpkz0ic0qidxirtvc/Utax-Treiber.zip?rlkey=eb3ly2i0menvoxbypdhtb7ozl&st=biozozb8&dl=1', '%BASE_PATH%Utax-treiber.zip')"
|
||||
|
||||
:: Pruefen, ob der Download erfolgreich war
|
||||
if not exist "%BASE_PATH%Utax-treiber.zip" (
|
||||
echo Fehler: Der Treiber konnte nicht heruntergeladen werden!
|
||||
pause
|
||||
exit /b
|
||||
)
|
||||
|
||||
echo Entpacke den Treiber...
|
||||
powershell -Command "Expand-Archive -Path '%BASE_PATH%Utax-treiber.zip' -DestinationPath '%BASE_PATH%Utax-treiber' -Force"
|
||||
|
||||
:: Pruefen, ob das Entpacken erfolgreich war
|
||||
if not exist "%BASE_PATH%Utax-treiber" (
|
||||
echo Fehler: Das Entpacken ist fehlgeschlagen!
|
||||
pause
|
||||
exit /b
|
||||
)
|
||||
|
||||
echo Entferne die ZIP-Datei...
|
||||
del "%BASE_PATH%Utax-treiber.zip"
|
||||
|
||||
echo Treiber wurde erfolgreich heruntergeladen und entpackt.
|
||||
)
|
||||
|
||||
GOTO check_path
|
||||
|
||||
:check_path
|
||||
:: Pruefe, ob der Treiberordner existiert
|
||||
if not exist "%DRIVER_PATH%" (
|
||||
echo Fehler: Der Treiberordner "%DRIVER_PATH%" existiert nicht!
|
||||
pause
|
||||
exit /b
|
||||
)
|
||||
|
||||
:: Port erstellen
|
||||
echo Erstelle TCP/IP-Port...
|
||||
cscript "%WINDIR%\System32\Printing_Admin_Scripts\de-DE\prnport.vbs" -a -r %PRINTER_IP% -h %PRINTER_IP% -o raw
|
||||
|
||||
|
||||
:: Druckertreiber installieren (automatische INF-Suche)
|
||||
echo Installiere Druckertreiber aus: %DRIVER_PATH% ...
|
||||
pnputil /add-driver "%DRIVER_PATH%\Kx85_UPD_TA_8.5.2405_RC2_WHQL\64bit\*.inf" /install
|
||||
|
||||
:: Drucker installieren (inklusive der zusaetzlichen Drucker)
|
||||
for %%P in (%PRINTER_LIST%) do (
|
||||
echo Installiere Drucker: %%P ...
|
||||
rundll32 printui.dll,PrintUIEntry /if /b %%P /r "%PRINTER_IP%" /m %DRIVER_NAME%
|
||||
)
|
||||
|
||||
:: Nach Installation den Registry-Wert für SW-Drucker setzen
|
||||
echo Setze Standarddrucker-Einstellungen nach OH5 Standard...
|
||||
powershell -ExecutionPolicy Bypass -File "%BASE_PATH%do_default_printersettings.ps1" -PrinterName "%PRINTER_NAME%"
|
||||
|
||||
|
||||
:: Standarddrucker setzen
|
||||
set /p SET_DEFAULT="Soll '%PRINTER_NAME% (SW)' als Standard gesetzt werden? (J/N): "
|
||||
IF /I "%SET_DEFAULT%"=="J" GOTO set_default
|
||||
GOTO cleanup
|
||||
|
||||
:set_default
|
||||
rundll32 printui.dll,PrintUIEntry /y /n "%PRINTER_NAME% (SW)"
|
||||
rundll32 printui.dll,PrintUIEntry /Xs /n "%PRINTER_NAME% (SW)" attributes +Direct
|
||||
|
||||
echo "%PRINTER_NAME% (SW)" ist jetzt der Standarddrucker.
|
||||
|
||||
:cleanup
|
||||
:: Treiberordner loeschen, nur wenn der Benutzer "N" gewaehlt hat
|
||||
if "%DELETE_DRIVER_PATH%"=="1" (
|
||||
if exist "%DRIVER_PATH%" (
|
||||
echo Entferne den heruntergeladenen Treiberordner...
|
||||
rmdir /s /q "%DRIVER_PATH%"
|
||||
echo Treiberordner erfolgreich geloescht.
|
||||
)
|
||||
)
|
||||
|
||||
:end
|
||||
echo Installation abgeschlossen.
|
||||
pause
|
||||
38
Assets/UTAX/do_default_printersettings.ps1
Normal file
38
Assets/UTAX/do_default_printersettings.ps1
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
param (
|
||||
[string]$PrinterName
|
||||
)
|
||||
|
||||
try {
|
||||
# Druckername fuer Schwarz-Weiß und Farbe generieren
|
||||
$PrinterNameSW = "$PrinterName (SW)"
|
||||
$PrinterNameColor = "$PrinterName (Farbe)"
|
||||
|
||||
# Aktuellen Skript-Ordner ermitteln
|
||||
#$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||
#$ConfigFile = "$ScriptPath\SwConfig.xml"
|
||||
|
||||
Write-Host "Setze Standard-Druckeinstellungen fuer: $PrinterNameSW ..."
|
||||
|
||||
# Setze den Druckmodus fuer Schwarz-Weiß auf Monochrome
|
||||
# Set-PrintConfiguration -PrinterName $PrinterNameSW -Color $false
|
||||
# Set-PrinterProperty -PrinterName $PrinterNameSW -PropertyName "PrintColorMode" -Value "Monochrome"
|
||||
# Set-PrintConfiguration -PrinterName $PrinterName -PrintTicketXML (Get-Content $ConfigFile -Raw)
|
||||
|
||||
|
||||
|
||||
# Duplex fuer Schwarz-Weiß deaktivieren
|
||||
Set-PrintConfiguration -PrinterName $PrinterNameSW -DuplexingMode OneSided
|
||||
Set-PrintConfiguration -PrinterName $PrinterNameSW -Color Monochrome
|
||||
|
||||
|
||||
|
||||
Write-Host "Setze Standard-Druckeinstellungen fuer: $PrinterNameColor ..."
|
||||
|
||||
# Duplex fuer Farbe deaktivieren
|
||||
Set-PrintConfiguration -PrinterName $PrinterNameColor -DuplexingMode OneSided
|
||||
|
||||
Write-Host "Fertig! Alle Einstellungen wurden erfolgreich gesetzt."
|
||||
}
|
||||
catch {
|
||||
Write-Host "Fehler: Konnte die Druckereinstellung nicht ändern. ueberpruefe, ob die Drucker '$PrinterNameSW' und '$PrinterNameColor' existieren!"
|
||||
}
|
||||
78
Assets/UTAX/test.ps1
Normal file
78
Assets/UTAX/test.ps1
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
Add-Type -Language CSharp -TypeDefinition @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class PrinterConfig {
|
||||
[DllImport("winspool.drv", SetLastError = true)]
|
||||
public static extern bool OpenPrinter(string pPrinterName, out IntPtr hPrinter, IntPtr pDefault);
|
||||
|
||||
[DllImport("winspool.drv", SetLastError = true)]
|
||||
public static extern bool ClosePrinter(IntPtr hPrinter);
|
||||
|
||||
[DllImport("winspool.drv", SetLastError = true)]
|
||||
public static extern int DocumentProperties(IntPtr hwnd, IntPtr hPrinter, string pDeviceName,
|
||||
IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);
|
||||
|
||||
public const int DM_COLOR = 0x800;
|
||||
public const short DMCOLOR_MONOCHROME = 1;
|
||||
public const short DMCOLOR_COLOR = 2;
|
||||
|
||||
public const int DM_IN_BUFFER = 0x8;
|
||||
public const int DM_OUT_BUFFER = 0x2;
|
||||
|
||||
public static void SetPrinterToMonochrome(string printerName) {
|
||||
IntPtr hPrinter;
|
||||
if (!OpenPrinter(printerName, out hPrinter, IntPtr.Zero)) {
|
||||
throw new Exception("Drucker konnte nicht geöffnet werden.");
|
||||
}
|
||||
|
||||
// Erste Abfrage: Wie groß ist der DEVMODE?
|
||||
int sizeNeeded = DocumentProperties(IntPtr.Zero, hPrinter, printerName, IntPtr.Zero, IntPtr.Zero, 0);
|
||||
if (sizeNeeded <= 0) {
|
||||
ClosePrinter(hPrinter);
|
||||
throw new Exception("Konnte DEVMODE-Größe nicht ermitteln.");
|
||||
}
|
||||
|
||||
// Speicher allokieren für Input & Output DEVMODE
|
||||
IntPtr pDevModeInput = Marshal.AllocHGlobal(sizeNeeded);
|
||||
IntPtr pDevModeOutput = Marshal.AllocHGlobal(sizeNeeded);
|
||||
|
||||
// DEVMODE vom Drucker holen
|
||||
int getDevModeResult = DocumentProperties(IntPtr.Zero, hPrinter, printerName, pDevModeInput, IntPtr.Zero, 0);
|
||||
if (getDevModeResult < 0) {
|
||||
ClosePrinter(hPrinter);
|
||||
Marshal.FreeHGlobal(pDevModeInput);
|
||||
Marshal.FreeHGlobal(pDevModeOutput);
|
||||
throw new Exception("Konnte DEVMODE nicht vom Drucker abrufen.");
|
||||
}
|
||||
|
||||
// Lesen und bearbeiten
|
||||
int offset = 104; // typischer Offset von dmColor innerhalb DEVMODE (abhängig vom Treiber!)
|
||||
byte[] devmodeData = new byte[sizeNeeded];
|
||||
Marshal.Copy(pDevModeInput, devmodeData, 0, sizeNeeded);
|
||||
|
||||
// Setze das dmColor-Feld auf MONOCHROME (1)
|
||||
devmodeData[offset + 0] = (byte)(DMCOLOR_MONOCHROME & 0xFF); // Low Byte
|
||||
devmodeData[offset + 1] = (byte)((DMCOLOR_MONOCHROME >> 8) & 0xFF); // High Byte
|
||||
|
||||
// Setze dmFields (aktiviert die Einstellung) — Bit 11 (0x800)
|
||||
devmodeData[76] |= 0x00; // low byte bleibt gleich
|
||||
devmodeData[77] |= 0x08; // high byte |= 0x08 → 0x800 aktiviert DM_COLOR
|
||||
|
||||
Marshal.Copy(devmodeData, 0, pDevModeInput, sizeNeeded);
|
||||
|
||||
// Setzen des neuen DEVMODEs
|
||||
int setResult = DocumentProperties(IntPtr.Zero, hPrinter, printerName, pDevModeOutput, pDevModeInput, DM_IN_BUFFER | DM_OUT_BUFFER);
|
||||
if (setResult < 0) {
|
||||
throw new Exception("Setzen des bearbeiteten DEVMODE fehlgeschlagen.");
|
||||
}
|
||||
|
||||
ClosePrinter(hPrinter);
|
||||
Marshal.FreeHGlobal(pDevModeInput);
|
||||
Marshal.FreeHGlobal(pDevModeOutput);
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
# 🎯 Name deines Druckers
|
||||
[PrinterConfig]::SetPrinterToMonochrome("2508ci KX")
|
||||
Loading…
Add table
Add a link
Reference in a new issue