Page 1 of 3 123>
Topic Options
#132892 - 2005-01-24 06:05 PM Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Hi Guys
I have seen countles network printer scripts, that you and the other maestros have publish, so I though you could help to verify this script I am trying to use to mapp printers!?
Of course the script is something you guys have writen, I am just trying to make it run on my enviroment..
I have got two print servers per floor, and about 40-50 network printers. I have divided printers on Security Zones (AD Groups) and mapping the users to the printers near by, based on security groups ! (Hope it makes sense)!? Because I got two print servers I want the script to provide me with load balancing and error checking !!? The script below is something you guys have writen, and I have made some modification to see if I can get the reasults I want,but I am not quite sure if it going to work. Could you please have a look/advice/sugest !?
Thanks in advance
Bestia

IF INGROUP("PF4Z3")
CLS
AT (11,30) "Adding Printers"
$rc=addprinterconnection("\\SRIM6122\PRIM1551") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1551")
$rc=addprinterconnection("\\SRIM6109\PRIM1550") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1550")
$rc=addprinterconnection("\\SRIM6122\PRIM1782") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1782")
$rc=addprinterconnection("\\SRIM6109\PRIM1347") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1347")
setdefaultprinter("\\SRIM6122\PRIM1551") If @error<>0 setdefaultprinter("\\SRIM6109\PRIM1550")
AT (13,30) "Default Printer HP4050N"
EndIf

What is happening at the mo is that it only mapps the first print and then it exits ! The users can be members of more then one AD GROUP !!

Top
#132893 - 2005-01-24 06:28 PM Re: Network Print Mapping
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Endif after each IF statement

$rc=addprinterconnection("\\SRIM6122\PRIM1551") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1551") ENDIF

$rc=addprinterconnection("\\SRIM6109\PRIM1550") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1550") ENDIF

etc..
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#132894 - 2005-01-25 12:13 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Yes, thank you for the quick reply! I have placed the Endif in the end of each line, and now it mapps the printers within the group. The next question would be..if users are members of more then one printer groups, would the script continue to run or wll exit after mapping the prnters on the first group !? So te script would look like..

IF INGROUP("PF4Z3")
CLS
AT (11,30) "Adding Printers"
$rc=addprinterconnection("\\SRIM6122\PRIM1551") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1551") ENDIF
$rc=addprinterconnection("\\SRIM6109\PRIM1550") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1550") ENDIF
$rc=addprinterconnection("\\SRIM6122\PRIM1782") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1782") ENDIF
$rc=addprinterconnection("\\SRIM6109\PRIM1347") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1347") ENDIF
setdefaultprinter("\\SRIM6122\PRIM1551") If @error<>0 setdefaultprinter("\\SRIM6109\PRIM1550") ENDIF
AT (13,30) "Default Printer HP4050N"
EndIf

IF INGROUP("PF4Z4")
CLS
AT (11,30) "Adding Printers"
$rc=addprinterconnection("\\SRIM6122\PRIM1551") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1551") ENDIF
$rc=addprinterconnection("\\SRIM6109\PRIM1550") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1550") ENDIF
$rc=addprinterconnection("\\SRIM6122\PRIM1782") If @error<>0 addprinterconnection("\\SRIM6109\PRIM1782") ENDIF
$rc=addprinterconnection("\\SRIM6109\PRIM1347") If @error<>0 addprinterconnection("\\SRIM6122\PRIM1347")ENDIF
setdefaultprinter("\\SRIM6122\PRIM1551") If @error<>0 setdefaultprinter("\\SRIM6109\PRIM1550") ENDIF
AT (13,30) "Default Printer HP4050N"
EndIf


Edited by bestia (2005-01-25 12:17 AM)

Top
#132895 - 2005-01-25 05:01 AM Re: Network Print Mapping
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
This is a flawed approach. The ADDPRINTERCONNECTION can fail for various reasons (e.g. user not allowed to install printer drivers) though the user can still print. Or, the ADDPRINTERCONNECTION can succeed but the print server is unable to process the print jobs, e.g. spooler is stopped.
_________________________
There are two types of vessels, submarines and targets.

Top
#132896 - 2005-01-25 10:40 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Jens,
I do take your point, but not having the inside knwoledge of KIX as you guys do, can you advice a better way !?? I have a large network, with different buildings and floor, so it's important for me to have a control or better print management, with two print servers per floor I provide the load balance, but I want that to be transmited to script!
I have tested the posibility of the spooler service being stoped on the print server, and it will automatically fail to the other server during the script execution !!
Regards,
Bestia


Edited by bestia (2005-01-25 10:43 AM)

Top
#132897 - 2005-01-25 10:43 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

if users are members of more then one printer groups, would the script continue to run or wll exit after mapping the prnters on the first group !?



Other than where there is an error KiXtart scripts will run from start to finish unless you include a Return, Quit or Exit statement.

Both your IF INGROUP(...) conditionals will be evaluated. If the user is a member of both groups, then both sets of mappings will be done.

If you only ever want one set of mappings to be done (the conditions are mutually exclusive) then use the SELECT / ENDSELECT construct and arrange the tests in the order of their priority.

You should pop a message out somewhere if the mapping fails to both servers.

Here is an example using SELECT which also outputs error/success status':
Code:
Buggy code removed



Edited by Richard H. (2005-01-25 11:17 AM)

Top
#132898 - 2005-01-25 10:48 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Richard,
That's fab ! I'll test it right away.. Just a quick question, will this fail over to the other print server if the first one is not available !? I can see it in you script, but just want to make sure ?
Rgds,
Bestia

Top
#132899 - 2005-01-25 10:55 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Also, another question if I may!?
The first three letters of the Security Group identify the Building and the Floor...Building Poultry (P), Floor 4 (F4)..PF4 then the zone number..Z3 so PF4Z3, I have seen the use of CASE Select before, but I have not been able to come up with something that would make the script to jump straight to the relevant floor and zone !? Is it posible???

Top
#132900 - 2005-01-25 10:59 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
As you can see the printer list is just a comma seperated set of pairs, the primary path and the backup path seperated with a pipe (aka vertical bar "|").

To test it, just set one of the primary paths to an invalid server name or printer share name and see what happens

The script maps sets the first printer that successfully maps as the default printer, so make the firest printe in the list the one that you want as the default.

Top
#132901 - 2005-01-25 11:13 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
I have just tested the script and you are right, it fails automatically to the other printer, wich is fine, and it sets the default printer. But as you can see there are more then one printer per zone,and I would like to mapp all the printers that the user has access too !? I also get this error..
Mapping primary printer path \\SRIM6122\PRIM1551 *FAILED*
Mapping alternative printer path \\SRIM6109\PRIM1551 OK
Setting printer as default
ERROR : invalid method/function call: missing ')'!
Script: \\srim4790\scripts$\netprint.kix
Line : 31

Top
#132902 - 2005-01-25 11:14 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Also, another question if I may!?
The first three letters of the Security Group identify the Building and the Floor...Building Poultry (P), Floor 4 (F4)..PF4 then the zone number..Z3 so PF4Z3, I have seen the use of CASE Select before, but I have not been able to come up with something that would make the script to jump straight to the relevant floor and zone !? Is it posible???




Yes.

You should zero fill numbers so that they are the max width you would expect, so your groups would be PF04Z03 - this makes it soooo much easier to script.

Here is an example of a way to extract the information:
Code:
Break ON

$iIndex=0
$sGroup=EnumGroup($iIndex)
While $sGroup AND Not @ERROR
; Drop domain
If InStr($sGroup,"\") $sGroup=SubStr($sGroup,InStr($sGroup,"\")+1) EndIf
; If Second letter is a "F" and fourth letter is a "Z" then it is a location
If SubStr($sGroup,2,1)="F" AND SubStr($sGroup,4,1)="Z"
$sBuilding=SubStr($sGroup,1,1)
$sFloor=SubStr($sGroup,3,1)
$sZone=SubStr($sGroup,5,1)
EndIf
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop

If $sBuilding
"This user is located: " ?
" Building: "+$sBuilding ?
" Floor: "+$sFloor ?
" Zone: "+$sZone ?
Else
"NO LOCATION INFO FOR THIS USER!" ?
EndIf



[edit] Fixed incorrect substring for "$sFloor" [/edit]


Edited by Richard H. (2005-01-25 12:59 PM)

Top
#132903 - 2005-01-25 11:16 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

I have just tested the script and you are right, it fails automatically to the other printer, wich is fine, and it sets the default printer. But as you can see there are more then one printer per zone,and I would like to mapp all the printers that the user has access too !? I also get this error..
Mapping primary printer path \\SRIM6122\PRIM1551 *FAILED*
Mapping alternative printer path \\SRIM6109\PRIM1551 OK
Setting printer as default
ERROR : invalid method/function call: missing ')'!
Script: \\srim4790\scripts$\netprint.kix
Line : 31




It should map all printers, but there is a typo in the code.

Try this:
Code:
CLS 

Select
Case Not InGroup("PF4Z3")
$asPrinterList= "\\SRIM6122\PRIM1551|\\SRIM6109\PRIM1551",
"\\SRIM6109\PRIM1550|\\SRIM6122\PRIM1550",
"\\SRIM6122\PRIM1782|\\SRIM6109\PRIM1782",
"\\SRIM6109\PRIM1347|\\SRIM6122\PRIM1347"
Case InGroup("PF4Z4")
$asPrinterList= "\\SRIM6122\PRIM1551|\\SRIM6109\PRIM1551",
"\\SRIM6109\PRIM1550|\\SRIM6122\PRIM1550",
"\\SRIM6122\PRIM1782|\\SRIM6109\PRIM1782",
"\\SRIM6109\PRIM1347|\\SRIM6122\PRIM1347"
EndSelect

$iDefaultDone=0
For Each $asPrinterPair In $asPrinterList
$asPrinterPair=Split($asPrinterPair,"|")
"Mapping primary printer path "+$asPrinterPair[0]
If AddPrinterConnection($asPrinterPair[0])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"Mapping alternative printer path "+$asPrinterPair[1]
If AddPrinterConnection($asPrinterPair[1])
" " Color r+/n "*ALSO FAILED*" Color w/n @CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
If Not $iDefaultDone
"Setting printer as default"
If SetDefaultPrinter($asPrinterPair[1])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"ERROR: Could not set printer as default."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
$iDefaultDone=1
EndIf
EndIf
EndIf
Else
" " Color g+/n "OK" Color w/n @CRLF
"Setting printer as default"
If Not $iDefaultDone
If SetDefaultPrinter($asPrinterPair[0])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"ERROR: Could not set printer as default."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
$iDefaultDone=1
EndIf
EndIf
EndIf
Next


Top
#132904 - 2005-01-25 11:31 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Yeap, this one worked like a charm! Thank you. Should I add the code you send me with regard the floors in the end of this script ?
Top
#132905 - 2005-01-25 11:37 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Yeap, this one worked like a charm! Thank you. Should I add the code you send me with regard the floors in the end of this script ?




No.

That code was an example of how to parse the group name to get the information - it's a helping hand rather than a full solution.

If you cannot work out how to incorporate it into the script then take a step back and think about exactly what you are trying to do.

Once you are sure, post again with all the information - if we can't see the big picture any solutions are offer are going to be inappropriate or inefficient.

Top
#132906 - 2005-01-25 12:19 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Will do ! I will put together the script with few zones per floor and post it again, ao you can have a look. My main concern is that because there are so many floors and printer zones, the script will be quite big, so using the CASE SELECT or the code you provided, to make the script more eficent..
Thank you for your help
Rgds,
Bestia

Top
#132907 - 2005-01-25 12:57 PM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
No worries.

While you are looking at it, consider using a data file for the zone / printer mapping. Look up ReadProfileString() in the manual.

The benefit of using a data file is that you don't have to touch the script when you make any changes.

Your file would look something like this:
Code:

[LOCATION PF4Z3]
PRIM1551=\\SRIM6122\PRIM1551|\\SRIM6109\PRIM1551
PRIM1550=\\SRIM6109\PRIM1550|\\SRIM6122\PRIM1550
PRIM1782=\\SRIM6122\PRIM1782|\\SRIM6109\PRIM1782
PRIM1347=\\SRIM6109\PRIM1347|\\SRIM6122\PRIM1347

[LOCATION PF4Z4]
PRIM1551=\\SRIM6122\PRIM1551|\\SRIM6109\PRIM1551
PRIM1550=\\SRIM6109\PRIM1550|\\SRIM6122\PRIM1550
PRIM1782=\\SRIM6122\PRIM1782|\\SRIM6109\PRIM1782
PRIM1347=\\SRIM6109\PRIM1347|\\SRIM6122\PRIM1347


Top
#132908 - 2005-01-25 02:50 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
That sounds good ! And it would very usefull for the desktop support, since they don't have to understand/amend the script! I am looking into the Function, but I don't understand well enough how to create the ini file !?
Top
#132909 - 2005-01-25 03:25 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Richard,
I am really keen in the method described below!
Can you please help me put together a script based on it!?
I can easily create the security groups based on your sugestion..(PF04Z03), it just a matter of getting a sample together so I can work on it! I guess it would based on same principals as before..IfInGroup (PF04Z03) then the printers for that zone and then the code below wich will help the script to be more efficent !?

Top
#132910 - 2005-01-25 03:31 PM Re: Network Print Mapping
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11163
Loc: Boston, MA, USA
See the KiXtart Manual under READPROFILESTRING and WRITEPROFILESTRING.
_________________________
There are two types of vessels, submarines and targets.

Top
#132911 - 2005-01-25 03:41 PM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ok,

To create an "ini" file, just use Notepad or similar.

The following code is the same as before, but changed to retrieve the printer list from an INI file:
Code:
Break ON

CLS
$sPrinterIni=".\PrinterMap.ini"

$iIndex=0
$iDefaultDone=0
$sGroup=EnumGroup($iIndex)
While $sGroup AND Not @ERROR
; Drop domain
If InStr($sGroup,"\") $sGroup=SubStr($sGroup,InStr($sGroup,"\")+1) EndIf
; Check if there is a printer map for this group
For Each $sPrinter in Split(ReadProfileString($sPrinterIni,"LOCATION "+$sGroup,""),Chr(10))
If $sPrinter
$asPrinterPair=Split(ReadProfileString($sPrinterIni,"LOCATION "+$sGroup,$sPrinter),"|")
"Mapping primary printer path "+$asPrinterPair[0]
If AddPrinterConnection($asPrinterPair[0])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"Mapping alternative printer path "+$asPrinterPair[1]
If AddPrinterConnection($asPrinterPair[1])
" " Color r+/n "*ALSO FAILED*" Color w/n @CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
If Not $iDefaultDone
"Setting printer as default"
If SetDefaultPrinter($asPrinterPair[1])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"ERROR: Could not set printer as default."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
$iDefaultDone=1
EndIf
EndIf
EndIf
Else
" " Color g+/n "OK" Color w/n @CRLF
"Setting printer as default"
If Not $iDefaultDone
If SetDefaultPrinter($asPrinterPair[0])
" " Color r+/n "*FAILED*" Color w/n @CRLF
"ERROR: Could not set printer as default."+@CRLF
"Reason: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
$iDefaultDone=1
EndIf
EndIf
EndIf
EndIf
Next
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop

Exit 0



The way it works is:
1) Iterates through all the groups that the user is a member of.
2) Looks for a section in the "ini" file with a name "[LOCATION group]"
3) For every printer in the section it attempts to connect it, using the first printer that it successfully adds as the default printer.

Top
Page 1 of 3 123>


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

Who's Online
1 registered (Allen) and 289 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.045 seconds in which 0.012 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