| 
| 
| 
| #132933 - 2005-02-09 04:17 PM  Re: Network Print Mapping |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
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
 
 
 |  
| Top |  |  |  |  
| 
| 
| #132936 - 2005-02-09 04:34 PM  Re: Network Print Mapping |  
| bestia   Fresh Scripter
 
 Registered:  2004-08-26
 Posts: 36
 Loc:  Guildford, UK
 | 
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
 
 |  
| Top |  |  |  |  
| 
| 
| #132938 - 2005-02-10 02:55 PM  Re: Network Print Mapping |  
| bestia   Fresh Scripter
 
 Registered:  2004-08-26
 Posts: 36
 Loc:  Guildford, UK
 | 
Exuse my Ignorance..How do I do that !?  
 |  
| Top |  |  |  |  
| 
| 
| #132940 - 2005-02-10 04:06 PM  Re: Network Print Mapping |  
| bestia   Fresh Scripter
 
 Registered:  2004-08-26
 Posts: 36
 Loc:  Guildford, UK
 | 
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
 
 
 |  
| Top |  |  |  |  
| 
| 
| #132941 - 2005-02-10 04:08 PM  Re: Network Print Mapping |  
| bestia   Fresh Scripter
 
 Registered:  2004-08-26
 Posts: 36
 Loc:  Guildford, UK
 | 
Doh, right in front of me ! Thanks man, i have attached the code on the previous postRgds
 Bestia
   |  
| Top |  |  |  |  
| 
| 
| #132942 - 2005-02-14 01:42 PM  Re: Network Print Mapping |  
| bestia   Fresh Scripter
 
 Registered:  2004-08-26
 Posts: 36
 Loc:  Guildford, UK
 | 
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
   |  
| Top |  |  |  |  
 Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
 
 | 
| 
 
| 0 registered
and 550 anonymous users online. 
 | 
 |  |