Page 2 of 3 <123>
Topic Options
#132912 - 2005-01-25 04:19 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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

Top
#132913 - 2005-01-25 04:49 PM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#132914 - 2005-01-25 04:50 PM Re: Network Print Mapping
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#132915 - 2005-01-25 05:04 PM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#132916 - 2005-01-25 05:39 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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...


Edited by bestia (2005-01-25 05:46 PM)

Top
#132917 - 2005-01-25 06:55 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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

Top
#132918 - 2005-01-26 09:45 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#132919 - 2005-01-26 12:17 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Richard,
That's what I am getting and I haven't got a clue what it means !?

Top
#132920 - 2005-01-26 12:48 PM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#132921 - 2005-01-26 01:39 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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]


Top
#132922 - 2005-01-26 02:16 PM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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


Top
#132923 - 2005-01-26 02:44 PM Re: Network Print Mapping
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
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


_________________________
Eric

Top
#132924 - 2005-01-26 04:24 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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






Top
#132925 - 2005-01-30 02:22 AM Re: Network Print Mapping
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.



_________________________
There are two types of vessels, submarines and targets.

Top
#132926 - 2005-01-31 09:55 AM Re: Network Print Mapping
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#132927 - 2005-02-08 11:12 AM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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!!

Top
#132928 - 2005-02-08 12:17 PM Re: Network Print Mapping
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
There is a udf GetDefaultPrinter() that returns exactly what you need ... Get it here
_________________________



Top
#132929 - 2005-02-08 03:27 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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 !!???

Top
#132930 - 2005-02-09 05:47 AM Re: Network Print Mapping
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#132931 - 2005-02-09 04:05 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
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...
Top
Page 2 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 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.025 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