[Gelöst] Lokale Drucker

Antworten
hawaii
Beiträge: 77
Registriert: 03 Dez 2013, 13:32

[Gelöst] Lokale Drucker

Beitrag von hawaii »

Hallo @ll,

normal finde ich mich ja mit Doku und Forum in Opsi echt gut zurecht, aber nach dem alles andere soweit passt kommen wir zum Thema "Lokale Drucker" und hier fehlt mir
irgendwie jeglicher Ansatz....
Es sollen lokale Drucker mit IP angelegt werden.

Vielleicht kann mir ja mal jemand auf die Sprünge helfen... :?

Danke schon mal und Grüßle!
Zuletzt geändert von hawaii am 03 Feb 2014, 17:00, insgesamt 1-mal geändert.
Benutzeravatar
tobias
Beiträge: 1291
Registriert: 20 Aug 2008, 12:36
Wohnort: Braunschweig
Kontaktdaten:

Re: Lokale Drucker

Beitrag von tobias »

Ich würde auf Batch oder Powershell zurückgreifen.

Powershell:
http://www.wiegehtdas.ch/how-to/windows ... owershell/

CMD:
http://znil.net/index.php?title=Windows ... tei_mappen


Hab jedoch beides nicht getestet ;)
hawaii
Beiträge: 77
Registriert: 03 Dez 2013, 13:32

Re: Lokale Drucker

Beitrag von hawaii »

Danke tobias für den Hinweis! Kann ich Powershell eigentlich auch irgendwie in winst nutzen? Also wie eine [DosInAnIcon] Anweisung?
Weisst du da was?
Fragen über Fragen, weil ich hätt das ganze halt gern einfach als Paket in opsi hinterlegt.

Grüßle
Benutzeravatar
tobias
Beiträge: 1291
Registriert: 20 Aug 2008, 12:36
Wohnort: Braunschweig
Kontaktdaten:

Re: Lokale Drucker

Beitrag von tobias »

Hi,

ja kannst du, schau dir mal die ExecWith Sektionen an. Die sind dazu gedacht Fremdsprachen innerhalb eines WINST Scriptes zu integrieren.
http://download.uib.de/opsi4.0/doc/html ... t-execwith


Gruß
Tobias
hawaii
Beiträge: 77
Registriert: 03 Dez 2013, 13:32

Re: Lokale Drucker

Beitrag von hawaii »

Ok, noch mal Danke. Das hat mir alles sehr weiter geholfen und ich hab jetzt mal ein Paket für Windows 7, 64-bit gebaut mit welchem ich den Treiber, den Port und auch den Drucker anlegen kann.
Das funktioniert auch alles.

Genauso hab ich gleich noch eine Deinstallationsroute dazu gebaut welches auch alle drei Teile sauber aus dem System entfernt. Die Deinstallationsroutine an sich funktioniert auch, allerdings habe ich Probleme damit zu prüfen ob es den Drucker bereits gibt....
Um den Rückgabewert von Powershell auszulesen habe ich mich dem Beispiel von hier bedient http://download.uib.de/opsi4.0/doc/html ... t-execwith
bzw. heisst es weiter unten, dass es funktionieren sollte wie bei dem Beispiel von execpython_hello.

Code: Alles auswählen

DefStringList pythonresult
Set pythonResult = GetOutStreamFromSection('execpython_hello -a "opt a“')
Wenn ich das allerdings so einbaue

Code: Alles auswählen

DefStringList $IsInstalled$
Set $IsInstalled$ = GetOutStreamFromSection('ExecWith_getPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit')

[ExecWith_getPrinter]
(Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'").PrinterStatus
Dann krieg ich beim Ausführen die Fehlermeldung

Code: Alles auswählen

Section   Sub "P:\printerkonicasmall\delsub3264.ins" (Command in line 8):
$IsInstalled$ = GetOutStreamFromSection('ExecWith_getPrinter "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit')
Section "ExecWith_getPrinter" not found
Führe ich das ExecWith einfach nur aus funktioniert es, aber ich brauch natürlich den Rückgabewert um die Entscheidung treffen zu können ob deinstalliert werden soll.

Code: Alles auswählen

ExecWith_getPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit

[ExecWith_getPrinter]
(Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'").PrinterStatus
Vielleicht hat ja noch jemand eine Idee, weil im Moment hängt es eigentlich nur noch daran. Alles andere funktioniert, daher hier schon mal die Skripte:

setup.ins

Code: Alles auswählen

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

[Actions]
requiredWinstVersion >= "4.11.2.6"

DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $INST_SystemType$
DefVar $INST_architecture$
DefVar $NameOfInstance$
DefVar $DriverName$
DefVar $DriverPath$
DefVar $PortIp$
DefStringList $IsInstalled$
DefVar $test$

Set $INST_SystemType$ = GetSystemType
set $INST_architecture$ = GetProductProperty("install_architecture","system specific")


Set $LogDir$ = "%SystemDrive%\tmp"

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
Set $ProductId$       = "printerKonicaSmall"
Set $MinimumSpace$    = "50 MB"
; the path were we find the product after the installation
Set $NameOfInstance$	= "Kopierer klein"
Set $DriverName$	= "KONICA MINOLTA C360SeriesPCL"
Set $DriverPath$	= "%Scriptpath%\KonicaSmall\KOAZ8J__.INF"
Set $PortIp$		= "xxx.xxx.xxx.xxx"
; ----------------------------------------------------------------

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
	isFatalError
	; Stop process and set installation status to failed
else
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$
	
	if FileExists("%ScriptPath%\delsub3264.ins")
		comment "Start uninstall sub section"
		Sub "%ScriptPath%\delsub3264.ins"
	endif
	
	comment "installing"

	if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
		Message "Installing " + $ProductId$ + " 64 Bit..."
		comment "Patch registry to allow local powershell scripts...."
		Registry_patch /64Bit
		comment "Installing driver...."
		DosInAnIcon_Treiber
		comment "Installing printer port...."
		comment $PowerShellPath$
		ExecWith_setPort "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Installing printer...."
		ExecWith_setPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Patch registry to disallow local powershell scripts...."		
		Registry_unpatch /64Bit
	endif
	
endif

[Registry_patch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "RemoteSigned"

[Registry_unpatch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "Restricted"

[DosInAnIcon_Treiber]
rundll32 printui.dll,PrintUIEntry /ia /m "$DriverName$" /h "x64" /v "Typ 3 - Benutzermodus" /f $DriverPath$

[ExecWith_setPort]
Write-Output "Creating printer port `"$NameOfInstance$`""
$port =([WMICLASS]"\\.\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name="$NameOfInstance$"
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress="$PortIp$"
$port.Put()

[ExecWith_setPrinter]
Write-Output "Creating printer `"$NameOfInstance$`""
$printer =([WMICLASS]"\\.\ROOT\cimv2:Win32_Printer").createInstance()
$printer.Name="$NameOfInstance$"
$printer.DriverName="$DriverName$"
$printer.DeviceID="$NameOfInstance$"
$printer.PortName="$NameOfInstance$"
$printer.Put()
uninstall.ins

Code: Alles auswählen

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib gmbh
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

[Actions]
requiredWinstVersion >= "4.11.2.6"

DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $INST_SystemType$
DefVar $INST_architecture$
DefVar $NameOfInstance$
DefVar $DriverName$
DefVar $DriverPath$
DefVar $PortIp$
DefStringList $IsInstalled$
DefVar $test$

Set $INST_SystemType$ = GetSystemType
set $INST_architecture$ = GetProductProperty("install_architecture","system specific")


Set $LogDir$ = "%SystemDrive%\tmp"

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
Set $ProductId$       = "printerKonicaSmall"
Set $MinimumSpace$    = "50 MB"
; the path were we find the product after the installation
Set $NameOfInstance$	= "Kopierer klein"
Set $DriverName$	= "KONICA MINOLTA C360SeriesPCL"
Set $DriverPath$	= "%Scriptpath%\KonicaSmall\KOAZ8J__.INF"
Set $PortIp$		= "xxx.xxx.xxx.xxx"
; ----------------------------------------------------------------


comment "Show product picture"
ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$

Message "Uninstalling " + $ProductId$ + " ..."

if FileExists("%ScriptPath%\delsub3264.ins")
	comment "Start uninstall sub section"
	Sub "%ScriptPath%\delsub3264.ins"
endif
delsub3264.ins

Code: Alles auswählen

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib gmbh
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

comment "Patch registry to allow local powershell scripts...."
Registry_patch /64Bit
;Set $IsInstalled$ = GetOutStreamFromSection('ExecWith_getPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit')
ExecWith_getPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
comment "Patch registry to disallow local powershell scripts...."
Registry_unpatch /64Bit
Set $test$ = takeString(0,$IsInstalled$)
Set $test$ = "3"

if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
	Message "Uninstalling " + $ProductId$ + " 64 Bit..."

	if ($test$ = "3")
		comment "Uninstall printer...."
		comment $test$
		comment "Patch registry to allow local powershell scripts...."
		Registry_patch /64Bit
		comment "Remove printer...."
		ExecWith_deletePrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Remove port...."
		ExecWith_deletePort "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Remove driver...."
		DosInAnIcon_Treiber
		comment "Patch registry to disallow local powershell scripts...."
		Registry_unpatch /64Bit
	else
		comment "Printer not found...."
	endif
endif

[ExecWith_getPrinter]
(Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'").PrinterStatus

[ExecWith_deletePrinter]
$printer = Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'"
$printer.delete()

[ExecWith_deletePort]
$port = Get-WmiObject Win32_TCPIPPrinterPort -Filter "Name='$NameOfInstance$'"
$port.delete()

[DosInAnIcon_Treiber]
rundll32 printui.dll,PrintUIEntry /dd /m "$DriverName$" /h "x64" /v "Typ 3 - Benutzermodus"

[Registry_patch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "RemoteSigned"

[Registry_unpatch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "Restricted"
hawaii
Beiträge: 77
Registriert: 03 Dez 2013, 13:32

Re: Lokale Drucker

Beitrag von hawaii »

Nevermind, ich hab gerade gefunden, dass ich auf 'nem Bug sitz ;-) viewtopic.php?f=6&t=5568&p=24895&hilit= ... ion#p24895
Ich habe die 3 Skripte jetzt noch mal umgebaut und die Abfrage aus dem delsub herausgenommen und jetzt funktioniert das Ganze auch!

Vielleicht hilft's ja dem ein oder anderen weiter :-)

Grüßle

setup.ins:

Code: Alles auswählen

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

[Actions]
requiredWinstVersion >= "4.11.2.6"

DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $INST_SystemType$
DefVar $INST_architecture$
DefVar $NameOfInstance$
DefVar $DriverName$
DefVar $DriverPath$
DefVar $PortIp$
DefStringList $IsInstalled$
DefVar $test$

Set $INST_SystemType$ = GetSystemType
set $INST_architecture$ = GetProductProperty("install_architecture","system specific")


Set $LogDir$ = "%SystemDrive%\tmp"

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
Set $ProductId$       = "printerKonicaSmall"
Set $MinimumSpace$    = "50 MB"
; the path were we find the product after the installation
Set $NameOfInstance$	= "Kopierer klein"
Set $DriverName$	= "KONICA MINOLTA C360SeriesPCL"
Set $DriverPath$	= "%Scriptpath%\KonicaSmall\KOAZ8J__.INF"
Set $PortIp$		= "xxx.xxx.xxx.xxx"
; ----------------------------------------------------------------

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
	isFatalError
	; Stop process and set installation status to failed
else
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$
	
	if FileExists("%ScriptPath%\delsub3264.ins")
		comment "Start uninstall sub section"
		Registry_patch /64Bit
		Set $IsInstalled$ = GetOutStreamFromSection('ExecWith_getPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit')
		comment $IsInstalled$
		Registry_unpatch /64Bit
		Sub "%ScriptPath%\delsub3264.ins"
	endif
	
	comment "installing"

	if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
		Message "Installing " + $ProductId$ + " 64 Bit..."
		comment "Patch registry to allow local powershell scripts...."
		Registry_patch /64Bit
		comment "Installing driver...."
		DosInAnIcon_Treiber
		comment "Installing printer port...."
		comment $PowerShellPath$
		ExecWith_setPort "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Installing printer...."
		ExecWith_setPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Patch registry to disallow local powershell scripts...."		
		Registry_unpatch /64Bit
	endif
	
endif

[Registry_patch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "RemoteSigned"

[Registry_unpatch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "Restricted"

[DosInAnIcon_Treiber]
rundll32 printui.dll,PrintUIEntry /ia /m "$DriverName$" /h "x64" /v "Typ 3 - Benutzermodus" /f $DriverPath$

[ExecWith_setPort]
Write-Output "Creating printer port `"$NameOfInstance$`""
$port =([WMICLASS]"\\.\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
$port.Name="$NameOfInstance$"
$port.SNMPEnabled=$false
$port.Protocol=1
$port.HostAddress="$PortIp$"
$port.Put()

[ExecWith_setPrinter]
Write-Output "Creating printer `"$NameOfInstance$`""
$printer =([WMICLASS]"\\.\ROOT\cimv2:Win32_Printer").createInstance()
$printer.Name="$NameOfInstance$"
$printer.DriverName="$DriverName$"
$printer.DeviceID="$NameOfInstance$"
$printer.PortName="$NameOfInstance$"
$printer.Put()

[ExecWith_getPrinter]
(Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'").PrinterStatus

uninstall.ins:

Code: Alles auswählen

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib gmbh
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

[Actions]
requiredWinstVersion >= "4.11.2.6"

DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $INST_SystemType$
DefVar $INST_architecture$
DefVar $NameOfInstance$
DefVar $DriverName$
DefVar $DriverPath$
DefVar $PortIp$
DefStringList $IsInstalled$
DefVar $test$

Set $INST_SystemType$ = GetSystemType
set $INST_architecture$ = GetProductProperty("install_architecture","system specific")


Set $LogDir$ = "%SystemDrive%\tmp"

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
Set $ProductId$       = "printerKonicaSmall"
Set $MinimumSpace$    = "50 MB"
; the path were we find the product after the installation
Set $NameOfInstance$	= "Kopierer klein"
Set $DriverName$	= "KONICA MINOLTA C360SeriesPCL"
Set $DriverPath$	= "%Scriptpath%\KonicaSmall\KOAZ8J__.INF"
Set $PortIp$		= "xxx.xxx.xxx.xxx"
; ----------------------------------------------------------------


comment "Show product picture"
ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$

Message "Uninstalling " + $ProductId$ + " ..."

if FileExists("%ScriptPath%\delsub3264.ins")
	comment "Start uninstall sub section"
	Registry_patch /64Bit
	Set $IsInstalled$ = GetOutStreamFromSection('ExecWith_getPrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit')
	comment $IsInstalled$
	Registry_unpatch /64Bit
	Sub "%ScriptPath%\delsub3264.ins"
endif

[ExecWith_getPrinter]
(Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'").PrinterStatus

[Registry_patch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "RemoteSigned"

[Registry_unpatch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "Restricted"
delsub3264.ins:

Code: Alles auswählen

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib gmbh
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/en/credits/

Set $test$ = takeString(0,$IsInstalled$)

if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
	Message "Uninstalling " + $ProductId$ + " 64 Bit..."

	if not ($test$ = "")
		comment "Uninstall printer...."
		comment $test$
		comment "Patch registry to allow local powershell scripts...."
		Registry_patch /64Bit
		comment "Remove printer...."
		ExecWith_deletePrinter "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Remove port...."
		ExecWith_deletePort "%System%\WindowsPowerShell\v1.0\powershell.exe" -command WINST /64Bit
		comment "Remove driver...."
		DosInAnIcon_Treiber
		comment "Patch registry to disallow local powershell scripts...."
		Registry_unpatch /64Bit
	else
		comment "Printer not found...."
	endif
endif

[ExecWith_getPrinter]
(Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'").PrinterStatus

[ExecWith_deletePrinter]
$printer = Get-WmiObject Win32_Printer -Filter "Name='$NameOfInstance$'"
$printer.delete()

[ExecWith_deletePort]
$port = Get-WmiObject Win32_TCPIPPrinterPort -Filter "Name='$NameOfInstance$'"
$port.delete()

[DosInAnIcon_Treiber]
rundll32 printui.dll,PrintUIEntry /dd /m "$DriverName$" /h "x64" /v "Typ 3 - Benutzermodus"

[Registry_patch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "RemoteSigned"

[Registry_unpatch]
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]
set "ExecutionPolicy" = "Restricted"
Benutzeravatar
SisterOfMercy
Beiträge: 1524
Registriert: 22 Jun 2012, 19:18

Re: [Gelöst] Lokale Drucker

Beitrag von SisterOfMercy »

You can also use wmic, just run wmic /? to see the possible options. Here some examples:

Code: Alles auswählen

"%SystemRoot%\system32\wbem\wmic.exe" computersystem set AutomaticManagedPagefile=False
"%SystemRoot%\system32\wbem\wmic.exe" pagefileset where name="C:\\pagefile.sys" set InitialSize=4096,MaximumSize=4096

; Remove default printers
"%SystemRoot%\system32\wbem\wmic.exe" printer where name="fax" delete /nointeractive
"%SystemRoot%\system32\wbem\wmic.exe" printer where name="Microsoft XPS Document Writer" delete /nointeractive
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!
Antworten