Page 1 of 1 1
Topic Options
#191584 - 2009-01-05 02:49 AM Logogn script fails at printer handling section
IBBscript Offline
Fresh Scripter

Registered: 2009-01-05
Posts: 5
Hi all,

as a newbie in scripting I am out of ideas right now.
The logon script below does the job fine until the printer handling section comes along. To make sure all user are getting the same network printers connected, the printer are being deleted and reconnected at each logon.
I have seen at this forum, printer handling seem to be a ongoing issue at all. For me it seems, according to the documentation, that the AddPrinterConnection and DelPrinterConnection is the right way to get it done.
The attached error code handling does not come up with error codes, maybe this is due to my misunderstanding of the syntax, even if the printer are not being deleted or connected when the script has finished.

Any commet is appreciated.

 Code:
 
;*************************************************************************
;  Script Name:   Buero.kix
;  Author:        FS
;  Date:          05.01.2009
;  Description:   Logon Script für die Mitarbeiter im kaufmännischen Bereich 
;*************************************************************************
 

BREAK ON
CLS



SETTITLE ("Logon von " + @FULLNAME)		;Define Display Window Name

SETCONSOLE ("ALWAYSONTOP")			;Define Display to stay on top

$PWtime = @MAXPWAGE - @PWAGE			; Calculate remaining Password time before change is required

; Display "User and Computer Informationen"

$Items = "USER-ID","Anmelde-Domäne","Name","","Berechtigung","Logon SERVER", "USER Sprache", "Passwort ändern in", "", "PC-Name", "Prozessor", "IP-Adresse", "LogonScript Pfad", "Akt. Systemdatum", "Akt. Systemzeit", "","Betriebssystem", "BUILD", "Service Pack"
$Values = @USERID, @LDOMAIN, @FULLNAME, "", @PRIV, @LSERVER, @USERLANG, $PWtime + " Tagen", "", @WKSTA, @CPU + " / " + @MHZ + " MHz", @IPADDRESS0 + " " + @IPADDRESS1 + " " + @IPADDRESS2 + " " + @IPADDRESS3 , @SCRIPTDIR + "\" + @SCRIPTNAME,  @DATE, @TIME, "", @PRODUCTTYPE, @BUILD,  @CSD
Disp( "Benutzer und Computer Informationen", $Items, $Values )


Color r+/n

; Network drive handling
?
?
?
?
; Server drive deletion
?
? "Server-Laufwerke werden gelöscht ..."		
?
USE * /DELETE

sleep 2

Color g+/n

; Server drive re-conection
? "Server-Laufwerke werden neu erstellt..." 	
?

Use I: "\\domain.net\install"
;USE K: "\\DC1\XEROX SCANNER"
Use L: "\\domain.net\Geschaeftsleitung"
Use M: "\\domain.net\schreibbuero"
Use P: "\\domain.net\Projekte"
Use Q: "\\domain.net\Qualitaet"
;USE R: "\\DC1\ARCHIV"
;USE S: "\\DC1\BUERO"
;USE T: "\\DC1\TECHNIK"
Use T: "\\domain.net\Projekte"
;USE U: "\\DC1\ustrich_datenbank"
Use U: "\\domain.net\ustrich"
Use V: "\\domain.net\Verwaltung"

? "Die Server-Laufwerke sind jetzt neu zugeordnet"


SLEEP 2


Color w+/n

; Display all drives of that specific computer
?
? "Die folgenden Laufwerke sind auf diesem Computer verfügbar:"

color g+/n

$Drives = GetObject("winmgmts:").ExecQuery("select Name,DriveType from Win32_LogicalDisk")

if @error <> 0
   ? @error + " / " @serror
else
   for each $Drive in $Drives

       $result = $Drive.Name + " ("
       select
          case $Drive.DriveType = 0
               $result = $result + "Unknown"
          case $Drive.DriveType = 1
               $result = $result + "No Root Directory"
          case $Drive.DriveType = 2
               $result = $result + "Removable Disk"
          case $Drive.DriveType = 3
               $result = $result + "Lokale Platte"
          case $Drive.DriveType = 4
               $result = $result + "Server Laufwerk"
          case $Drive.DriveType = 5
               $result = $result + "Compact Disk"
          case $Drive.DriveType = 6
               $result = $result + "RAM Disk"
       endselect
       $result = $result + ")"

       ? $result
   next
endif

$Drives = 0

color w+/n

; Printer handling
; Delete LAN printer one by one
?
? "Evtl. bestehende Netzwerk-Druckerverbindungen werden gelöscht..."	
?
Sleep 10

color r/n

If DelPrinterConnection ("\\domain.net\IBBP5002") = 0
? "KONICA bizhub 250 gelöscht !"
	If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


If DelPrinterConnection ("\\domain.net\IBBP5002-A3") = 0
? "KONICA bizhub 250 für A3 gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


If DelPrinterConnection ("\\domain.net\IBBP5002-A4-4auf1") = 0
? "KONICA bizhub 250 für A4-Doppelnutzen-Duplex gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5002-A4-D") = 0
? "KONICA bizhub 250 für A4-Duplex gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP1002") = 0
? "KYOCERA FS1118 bei Angi Hegel gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP1004") = 0
? "KYOCERA FS920 bei Ralf Werner gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP1006") = 0
? "KYOCERA FS920 bei Frank Hartung gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP1003") = 0
? "KYOCERA FS920 bei Mario Jung gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP1001") = 0
? "KYOCERA FS1200 auf für Etiketten u. Anderes gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


If DelPrinterConnection ("\\domain.net\HP5500") = 0
? "PLOTTER HP 5500 gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL") = 0
? "XEROX PCL gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A3") = 0
? "XEROX PCL für A3 gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-4auf1-D") = 0
? "XEROX PCL für -A4 Doppelnutzen, Duplex- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-D") = 0
? "XEROX PCL für -A4 Duplex- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-H") = 0
? "XEROX PCL für -A4 Heften- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-HuL") = 0
? "XEROX PCL für -A4 Heften und Lochen- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-HuL-D") = 0
? "XEROX PCL für -A4 geheftet und gelocht, Duplex- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-L") = 0
? "XEROX PCL für -A4 gelocht- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001-PCL-IBB_RG") = 0
? "XEROX PCL für -Schacht 2 Papier bunt- gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If DelPrinterConnection ("\\domain.net\IBBP5001") = 0
? "XEROX PS gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

Color w+/n

; Reconnect LAN printer, same for each business user
?
? "Neue Drucker werden installiert..."
?

color g+/n

SLEEP 10


If AddPrinterConnection ("\\domain.net\IBBP5002") = 0
? "KONICA bizhub 250 gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


If AddPrinterConnection ("\\domain.net\IBBP5002-A3") = 0
? "KONICA bizhub 250 für A3 gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5002-A4-4auf1") = 0
? "KONICA bizhub 250 für A4-Doppelnutzen-Duplex gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5002-A4-D") = 0
? "KONICA bizhub 250 für A4-Duplex gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


SLEEP 2


If AddPrinterConnection ("\\domain.net\IBBP1002") = 0
? "KYOCERA FS1118 bei Angi Hegel gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP1004") = 0
? "KYOCERA FS920 bei Ralf Werner gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP1006") = 0
? "KYOCERA FS920 bei Frank Hartung gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP1003") = 0
? "KYOCERA FS920 bei Mario Jung gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP1001") = 0
? "KYOCERA FS1200 auf für Etiketten u. Anderes gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


SLEEP 2


If AddPrinterConnection ("\\domain.net\HP5500") = 0
? "PLOTTER HP 5500 gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


SLEEP 2


If AddPrinterConnection ("\\domain.net\IBBP5001-PCL") = 0
? "XEROX PCL gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A3") = 0
? "XEROX PCL für A3 gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-4auf1-D") = 0
? "XEROX PCL für -A4 Doppelnutzen, Duplex- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-D") = 0
? "XEROX PCL für -A4 Duplex- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-H") = 0
? "XEROX PCL für -A4 Heften- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-HuL") = 0
? "XEROX PCL für -A4 Heften und Lochen- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-HuL-D") = 0
? "XEROX PCL für -A4 geheftet und gelocht, Duplex- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-A4-L") = 0
? "XEROX PCL für -A4 gelocht- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001-PCL-IBB_RG") = 0
? "XEROX PCL für -Schacht 2 Papier bunt- gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

If AddPrinterConnection ("\\domain.net\IBBP5001") = 0
? "XEROX PS gemappt !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf


color r+/n

; Delete old LPT mappings, software requirement
; Löschen alter LPT-Drucker 								
?
? "Löschen alter LPT-Drucker..."

USE LPT1 /Delete
USE LPT2 /Delete
USE LPT3 /Delete
USE LPT4 /Delete

color g+/n

; Reconnect LPT mappings, software requirement
; Neuzuordnung von LPT-Druckern							
?
? "Neuzuordnung von LPT-Druckern"

Use LPT1: "\\domain.net\IBBP1004"
Use LPT2: "\\domain.net\IBBP5001"
Use LPT3: "\\domain.net\IBBP1003"
Use LPT4: "\\domain.net\HP5500"

color w+/n

? "==========   Fertig   ======================================"
?

?"So, das war´s ! "
?


SLEEP 2



; FFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFF  
; Function to display informations on top of the script

Function Disp( $Title, $ItemsToDisplay, $ValuesToDisplay )

Color b+/n
Box(0,0,24,79,full)

$Count = 0
Color y+/n
At( 1,22) $Title

For Each $Item in $ItemsToDisplay
   Color g+/n
   At( $Count+3, 5 ) $Item
   Color w+/n
   At( $Count+3, 28) $ValuesToDisplay[ $Count ]
   $Count = $Count + 1
Next

sleep 5

EndFunction
; FFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFF 



BEEP


Sleep 5

exit 0


Cheers

Top
#191585 - 2009-01-05 02:57 AM Re: Logogn script fails at printer handling section [Re: IBBscript]
IBBscript Offline
Fresh Scripter

Registered: 2009-01-05
Posts: 5
Just some additional info:

Talking about a W3k3 Active Directory Domain.
Server is based W2k3 R2, is Printserver, Domain Controller, Fileserver, DHCP and DNS. It´s running stable and with good performance.
All Clients are XPpro SP3. DFS is successfully in use.
LAN is a GBit fiber backbone, straight from the server to the clients.

Top
#191587 - 2009-01-05 03:28 AM Re: Logogn script fails at printer handling section [Re: IBBscript]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
As to the error codes...

 Code:
If DelPrinterConnection ("\\domain.net\IBBP5002-A4-4auf1") = 0
? "KONICA bizhub 250 für A4-Doppelnutzen-Duplex gelöscht !"
If @ERROR <> 0
		Color r+/w+
   		? @ERROR + " / " @SERROR
	EndIf
EndIf

Should be more like this....

 Code:
If DelPrinterConnection ("\\domain.net\IBBP5002-A4-4auf1") = 0
  ? "KONICA bizhub 250 für A4-Doppelnutzen-Duplex gelöscht !"
Else
  ? @ERROR + " / " @SERROR
EndIf


You have to write the @Error immediatly after whatever execution created the error, otherwise you are getting the result of output to the screen.

I would start by redoing your error traps and see what you are getting back.

Another thing to think about would be to see if a printer is already installed and if it is then skip that printer and move on to the next one/task.


Edited by Gargoyle (2009-01-05 03:30 AM)
Edit Reason: typos
_________________________
Today is the tomorrow you worried about yesterday.

Top
#191592 - 2009-01-05 09:15 AM Re: Logogn script fails at printer handling section [Re: Gargoyle]
IBBscript Offline
Fresh Scripter

Registered: 2009-01-05
Posts: 5
Gargoyle,
thx for the immediate reply.

I´ll test ASAP and will come back with the result.

I´m investigating how to check if the printer already installed in order to avoid deletion and reconnecting.
In case you want to, it would be nice to point me to the right direction.

Cheers.

Top
#191602 - 2009-01-05 12:11 PM Re: Logogn script fails at printer handling section [Re: IBBscript]
IBBscript Offline
Fresh Scripter

Registered: 2009-01-05
Posts: 5
Tested with correct error handling.

Result: At clients where the printers are availalbe I get from the "delete printer" section an error 997 (Overlapped I/O operation is in progress) for each printer which should be deleted.
The section for printer reconnect did not came up with an error but did not execute the AddPrinterConnection command, no printer added.

Top
#191603 - 2009-01-05 12:48 PM Re: Logogn script fails at printer handling section [Re: IBBscript]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Run "msiexec /regserver" from a command line, otherwise run sfc /scannow and then "msiexec /regserver". The MSI engine actually has two processes - one runs as a service, and the other runs under the user account. It's possible that one (or both) of these are no longer loading properly, or .dll's have become corrupt, or registry settings for the service are invalid, etc.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#191604 - 2009-01-05 02:34 PM Re: Logogn script fails at printer handling section [Re: Gargoyle]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
While it's absolutely best practice to check your error status immediately after returning from a function call, output statements will not set the error status. This can be verified by the following little script:
 Code:
Status(2)
'this,' ?
'that,' ?
'the other thing...' ?
'Oh, BTW, the function result was "' @SERROR '"' ?

Function Status($Val)
  Exit $Val
EndFunction

The function "STATUS" simply returns the parameter as the exit code.

Glenn

PS - think about it.. if a print statement set the error result, how could you print the error result using the macro?? ;\)
_________________________
Actually I am a Rocket Scientist! \:D

Top
#191611 - 2009-01-05 05:17 PM Re: Logogn script fails at printer handling section [Re: Glenn Barnas]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
The default printer is stored at:

HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device

All printer connections are at:

HKCU\Printers\Connections

Just enumerate the key.

Top
#191687 - 2009-01-07 10:48 AM Re: Logogn script fails at printer handling section [Re: BradV]
IBBscript Offline
Fresh Scripter

Registered: 2009-01-05
Posts: 5
Thx all,

the error messages are clarified now.
After a while it is pretty clear that the printer sharename used in my script is not working (\\\)
It´s clear now that the can not work properly!! It´s just luck which Domain Controller is answering the request from the client as each DC may reply due to the default DNS entires. My fault, not script related.

On the the script developemtn I will work on the next days, depending on the time I can/have to spend on it.

Cheers.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.065 seconds in which 0.029 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org