bestia
(Fresh Scripter)
2005-01-24 06:05 PM
Network Print Mapping

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 !!


Radimus
(KiX Supporter)
2005-01-24 06:28 PM
Re: Network Print Mapping

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..


bestia
(Fresh Scripter)
2005-01-25 12:13 AM
Re: Network Print Mapping

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


Sealeopard
(KiX Master)
2005-01-25 05:01 AM
Re: Network Print Mapping

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.

bestia
(Fresh Scripter)
2005-01-25 10:40 AM
Re: Network Print Mapping

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


Richard H.Administrator
(KiX Supporter)
2005-01-25 10:43 AM
Re: Network Print Mapping

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



bestia
(Fresh Scripter)
2005-01-25 10:48 AM
Re: Network Print Mapping

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


bestia
(Fresh Scripter)
2005-01-25 10:55 AM
Re: Network Print Mapping

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???


Richard H.Administrator
(KiX Supporter)
2005-01-25 10:59 AM
Re: Network Print Mapping

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.


bestia
(Fresh Scripter)
2005-01-25 11:13 AM
Re: Network Print Mapping

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


Richard H.Administrator
(KiX Supporter)
2005-01-25 11:14 AM
Re: Network Print Mapping

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]


Richard H.Administrator
(KiX Supporter)
2005-01-25 11:16 AM
Re: Network Print Mapping

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



bestia
(Fresh Scripter)
2005-01-25 11:31 AM
Re: Network Print Mapping

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 ?

Richard H.Administrator
(KiX Supporter)
2005-01-25 11:37 AM
Re: Network Print Mapping

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.


bestia
(Fresh Scripter)
2005-01-25 12:19 PM
Re: Network Print Mapping

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


Richard H.Administrator
(KiX Supporter)
2005-01-25 12:57 PM
Re: Network Print Mapping

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



bestia
(Fresh Scripter)
2005-01-25 02:50 PM
Re: Network Print Mapping

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 !?

bestia
(Fresh Scripter)
2005-01-25 03:25 PM
Re: Network Print Mapping

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 !?


Sealeopard
(KiX Master)
2005-01-25 03:31 PM
Re: Network Print Mapping

See the KiXtart Manual under READPROFILESTRING and WRITEPROFILESTRING.

Richard H.Administrator
(KiX Supporter)
2005-01-25 03:41 PM
Re: Network Print Mapping

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.


bestia
(Fresh Scripter)
2005-01-25 04:19 PM
Re: Network Print Mapping

Thank you Richard,
This is a sample of printer.ini I intend to use based on what you send me earlier..Please verify if it is correct !?

[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


Richard H.Administrator
(KiX Supporter)
2005-01-25 04:49 PM
Re: Network Print Mapping

Uh yeah. It looks the same to me.

Save it as a file called "PrinterMap.ini" in the same directory as the script and run the script. If you are a member of PF4Z3 or PF4Z4 it should attempt to map the printers.

When you deploy this live you will need to change the file name variable $sPrinterIni to reference the path to the data file.


Les
(KiX Master)
2005-01-25 04:50 PM
Re: Network Print Mapping

Should the printer not be assigned based on where the computer is and no who the user is? There are many posts related to mapping printers to computers instead of users.

Richard H.Administrator
(KiX Supporter)
2005-01-25 05:04 PM
Re: Network Print Mapping

Probably.

I also thought that AD had built-in facilities for location based resources, but I'm an AD numpty so I'm not going to stick my head above that parapet.


bestia
(Fresh Scripter)
2005-01-25 05:39 PM
Re: Network Print Mapping

Yes, it would have been easier to mapp the printers based on computers, but the naming standard that the company chose to use, was not what I asked for..Based on location etc... so it's almost imposible to that..at least as far as I know!! I have all the previous script posted here, and there are some great examples, but none is realy relevant to my enviroment...
To make things a bit more clear... These Security groups are based on zones! These zones are defined based on the location of the users/computers, basically a bunch of users are mapped to the nearest printer, as default and few other printers near by. During the migration process, the desktop team will find what default printer user uses, and add the user to the relevant AD Security Group..So if the user is on the third floor, near a printer called PRIM1234, which uses SRIM5678/SRIM4567 as print server then the users is added to the AD Security/Print Zone where that printer belongs to! Hope it makes sense !? I just could not think of anything else to make this work...


bestia
(Fresh Scripter)
2005-01-25 06:55 PM
Re: Network Print Mapping

Hi Richard,
I created the ini file and saved it on the same dir as the script, then run the script few time but no joy.. It just exits immediatly !!! I have included the scripts..well your scripts, in case you wanted to have a look..
Rgds,
Bestia

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

and printermap.ini....

[LOCATION PF3Z1]
PRIM1556=\\SRIM6110\PRIM1556|\\SRIM6111\PRIM1556
PRIM0936=\\SRIM6111\PRIM0936|\\SRIM6110\PRIM0936
PRIM1784=\\SRIM6110\PRIM1784|\\SRIM6111\PRIM1784

[LOCATION PF3Z3]
PRIM0171=\\SRIM6110\PRIM0171|\\SRIM6111\PRIM0171
PRIM1335=\\SRIM6111\PRIM1335|\\SRIM6110\PRIM1335
PRIM4156=\\SRIM6110\PRIM4156|\\SRIM6111\PRIM4156


[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


Richard H.Administrator
(KiX Supporter)
2005-01-26 09:45 AM
Re: Network Print Mapping

When you post script, included it between "code" tags - you will see a "Code" link in the "Instant UBB Code" area under the box that you type your message in. If you do this you will preserve the indenting in the code. Compare your posting to mine and you will see the difference. If you don't do this the code is very hard to read, and most readers will not try to help until you fix it up.

Now, I know the script works to a certain point because I've tested it.

You need to add some debugging statements to find out what it is doing. As you are getting nothing at all, I would check that the group enumeration is working as expected.

After the "BREAK ON" at the top of the script, add this line:
Code:
$bDEBUG=1



After this comment:
Code:
; Check if there is a printer map for this group



ADD this debug line:
Code:
If $bDEBUG Color w+/b "DEBUG: Looking for section [LOCATION "+$sGroup+"]" Color w/n ? EndIf



This will confirm whether the group enumeration is going as expected. If it is then start adding more debug statements around the code to work out which bit isn't working.

When you have finished debugging, change the "$bDEBUG=1" to "$bDEBUG=0" to switch off the debugging output, there is no need to remove the debug lines and they may be useful in the future.


bestia
(Fresh Scripter)
2005-01-26 12:17 PM
Re: Network Print Mapping

Richard,
That's what I am getting and I haven't got a clue what it means !?


Richard H.Administrator
(KiX Supporter)
2005-01-26 12:48 PM
Re: Network Print Mapping

Quote:

Richard,
That's what I am getting and I haven't got a clue what it means !?




What do you mean? What are you getting? Have you added the debug code? Is there any output now?

Make sure that you are running the script from a command line otherwise you won't see any errors or other output.


bestia
(Fresh Scripter)
2005-01-26 01:39 PM
Re: Network Print Mapping

Sorry Mate, fogot to attach the debug !! Duh..
Here it is..
DEBUG: Looking for section [LOCATION Domain Users]
DEBUG: Looking for section [LOCATION Everyone]
DEBUG: Looking for section [LOCATION Users]
DEBUG: Looking for section [LOCATION Administrators]
DEBUG: Looking for section [LOCATION Remote Desktop Users]
DEBUG: Looking for section [LOCATION DG-TransformIBDEV]
DEBUG: Looking for section [LOCATION PF3Z1]
DEBUG: Looking for section [LOCATION Citrix Administrators]
DEBUG: Looking for section [LOCATION WW-IT]
DEBUG: Looking for section [LOCATION Citrix Admins]
DEBUG: Looking for section [LOCATION PF3Z2]
DEBUG: Looking for section [LOCATION PF3ALL]
DEBUG: Looking for section [LOCATION PF3Z3]
DEBUG: Looking for section [LOCATION Avocent - View Only]
DEBUG: Looking for section [LOCATION PV-Wks-Admins]
DEBUG: Looking for section [LOCATION LOCAL]
DEBUG: Looking for section [LOCATION INTERACTIVE]
DEBUG: Looking for section [LOCATION Authenticated Users]
DEBUG: Looking for section [LOCATION Users]



Richard H.Administrator
(KiX Supporter)
2005-01-26 02:16 PM
Re: Network Print Mapping

Well, that all looks good.

Most likely problem is that the script is not finding the section in the INI file.

Check the file name, and make sure that Notepad (or whatever you used) has not added a ".txt" or ".doc" suffix. Check it by using DIR at the command line rather than Explorer which may hide the extensions.

You must use a simple text editor like Notepad to create the file - if you use Wordpad or Word or similar then it will add a load of garbage which will mean that the file cannot be interpreted properly.

To check if the script can see the file and it is ok, add the following just after the "$sPrinterIni=".\PrinterMap.ini"" line:
Code:
If ReadProfileString($sPrinterIni,"","")
If $bDEBUG
"DEBUG: The following sections appear in the INI file:" ?
"-----------------------------------------------------" ?
ReadProfileString($sPrinterIni,"","")
"-----------------------------------------------------" ?
EndIf
Else
If Exist($sPrinterIni)
"ERROR: INI file '"+$sPrinterIni+"' is empty or invalid!" ?
Else
"ERROR: INI file '"+$sPrinterIni+"' does not exist!" ?
EndIf
Exit 1
EndIf



maciep
(Korg Regular)
2005-01-26 02:44 PM
Re: Network Print Mapping

How is this script being launched? Just wondering because of how $sPrinterIni is being set. The '.\' notation can be an issue if not used correctly,

$sPrinterIni=".\PrinterMap.ini"

i would either change it to

Code:

$sPrinterIni= @scriptdir + "\PrinterMap.ini"



or at least make sure the script "knows" where it is right now.

Code:

$sPrinterIni=".\PrinterMap.ini"
if exist($sPrinterIni)
? found it
endif




bestia
(Fresh Scripter)
2005-01-26 04:24 PM
Re: Network Print Mapping

Quote:

How is this script being launched? Just wondering because of how $sPrinterIni is being set. The '.\' notation can be an issue if not used correctly,

$sPrinterIni=".\PrinterMap.ini"

i would either change it to

Code:

$sPrinterIni= @scriptdir + "\PrinterMap.ini"


This seems to make the trick !! It seems to mapp the printers on that zone..I will add some more zone and come back to you guys..thanks for the help.. I will leave the debug on for the moo...It seems to list all the groups the user is member of !!??
or at least make sure the script "knows" where it is right now.

Code:

$sPrinterIni=".\PrinterMap.ini"
if exist($sPrinterIni)
? found it
endif







Sealeopard
(KiX Master)
2005-01-30 02:22 AM
Re: Network Print Mapping

READPROFILESTRING requires the full path to the file. This is denoted in the KiXtart Manual.
Quote:


File name
A string that names the initialization file. If this parameter does not include a full path, Windows searches for the file in the Windows directory.





Richard H.Administrator
(KiX Supporter)
2005-01-31 09:55 AM
Re: Network Print Mapping

Quote:

READPROFILESTRING requires the full path to the file. This is denoted in the KiXtart Manual.
Quote:


File name
A string that names the initialization file. If this parameter does not include a full path, Windows searches for the file in the Windows directory.








This is actually untrue. A relative path is perfectly fine.

The problem occurs if you specify a path name with no path elements to it, i.e. a bare file name. In this case the API looks in the system default location(s) for the file.


bestia
(Fresh Scripter)
2005-02-08 11:12 AM
Re: Network Print Mapping

Richard,
The script that you wrote for me is going through the final testing before it goes live! So I would like to thank you and the other guys for your help! I just wanted to ask if would be posible to use "delprintconnection" on the code you supplyed, and if there is a way to check what the default printers by reading "HKEY_CURRENT_USER\Printers\Connections" and then using "delprintconnection" to clear the existing printers and mapp them again through the script, BUT ! remembering the default printer!! Is it posible !? It would save a lot of phone calls to helpdesk!!


JochenAdministrator
(KiX Supporter)
2005-02-08 12:17 PM
Re: Network Print Mapping

There is a udf GetDefaultPrinter() that returns exactly what you need ... Get it here

bestia
(Fresh Scripter)
2005-02-08 03:27 PM
Re: Network Print Mapping

While I can understand that, it doesn't really help me out for what I am trying to do. I am looking for a way to make the script read what the default printer is (GetDefaultPrinter), then use (delprinconnection to clear the existing connections then mapp the printers again, BUT ! making sure that the default printer is the same as before !? basically remebering what (GetdefaultPrinter) got!?
Posible !!???


Sealeopard
(KiX Master)
2005-02-09 05:47 AM
Re: Network Print Mapping

So, where's the problem? As you already know what the default printer is you can make sure that after reestablishing all printer that the default printer is being set again.

bestia
(Fresh Scripter)
2005-02-09 04:05 PM
Re: Network Print Mapping

The problem is I don't know how !? If I run GetDefaultprinter, and then delprintconnection, would it work !? and if so, how can I make sure that it does...? Sorry if this sounds a bit daft...

JochenAdministrator
(KiX Supporter)
2005-02-09 04:14 PM
Re: Network Print Mapping

The logic is quite simple ...

1. assign the result of GetDefaultPrinter to a variable.
2. Delete all Printers
3. Reconnect printers and if there is one that matches the stored variable set it as default.

That's at least what I read (sorry if I didn't follow the complete war and peace here )


AllenAdministrator
(KiX Supporter)
2005-02-09 04:17 PM
Re: Network Print Mapping

I think you may be over thinking this, as you already know what you want .. see if this will help you get in the right direction: (untested code)

Code:
 

break on

$default=GetDefaultPrinter()
? $default
$=DELPRINTERCONNECTION ($default)
? @serror
$=addprinterconnection($default)
? @serror
$=SETDEFAULTPRINTER($default)
? @serror

function GetDefaultPrinter()
$GetDefaultPrinter = join(split(readvalue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction



Les
(KiX Master)
2005-02-09 04:26 PM
Re: Network Print Mapping

...that is of course, assuming the printername and sharename are one and the same.

AllenAdministrator
(KiX Supporter)
2005-02-09 04:33 PM
Re: Network Print Mapping

HeHe... I did say the code was "untested". Just trying to get him going.

bestia
(Fresh Scripter)
2005-02-09 04:34 PM
Re: Network Print Mapping

Right Guys!
This is the code I am using, kindly supplyed to me by Richard (Thanks) I have done the initial testing and is doing exacly what I need, just I don't know how to add that (getdefault)+(delprintconnection) to it !
Obviously it is calling printemap.ini files for the printers....
Code:
Break ON
$bDEBUG=1
CLS
$sPrinterIni= @scriptdir + "\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
If $bDEBUG Color w+/b "DEBUG: Looking for section [LOCATION "+$sGroup+"]" Color w/n ? EndIf
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


maciep
(Korg Regular)
2005-02-10 02:47 PM
Re: Network Print Mapping

Why won't you put your code between the Code Tags? It's just about impossible to read it the way you have it posted now.

bestia
(Fresh Scripter)
2005-02-10 02:55 PM
Re: Network Print Mapping

Exuse my Ignorance..How do I do that !?

maciep
(Korg Regular)
2005-02-10 03:08 PM
Re: Network Print Mapping

Do you see the "Instant UBB Code" when you're posting? it's right below the text box you type in. Click on "Code" and you will get the Code Tags, put your code between them

"[CODE]"
your code
"[/CODE]"


bestia
(Fresh Scripter)
2005-02-10 04:06 PM
Re: Network Print Mapping

Code:

Break ON
$bDEBUG=1
CLS
$sPrinterIni= @scriptdir + "\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
If $bDEBUG Color w+/b "DEBUG: Looking for section [LOCATION "+$sGroup+"]" Color w/n ? EndIf
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



bestia
(Fresh Scripter)
2005-02-10 04:08 PM
Re: Network Print Mapping

Doh, right in front of me ! Thanks man, i have attached the code on the previous post
Rgds
Bestia


bestia
(Fresh Scripter)
2005-02-14 01:42 PM
Re: Network Print Mapping

Hi Guys,
I gather from your silence that what I wanted to add to the script is not an option, !!? Eh, well is really good as it is, and I will roll it out, and I do recommend it to anyone with complex printing enviroment. Thank you to everyone involved.
Best regards,
Bestia


Sealeopard
(KiX Master)
2005-02-15 12:44 AM
Re: Network Print Mapping

Pretty much anything is possible with KiXtart. You should look into the UDF Forum as there are various UDFs that deal with deleting printers and getting/setting default printers.