Page 3 of 3 <123
Topic Options
#132932 - 2005-02-09 04:14 PM Re: Network Print Mapping
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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 )


Edited by Jochen (2005-02-09 04:15 PM)
_________________________



Top
#132933 - 2005-02-09 04:17 PM Re: Network Print Mapping
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
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
#132934 - 2005-02-09 04:26 PM Re: Network Print Mapping
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
...that is of course, assuming the printername and sharename are one and the same.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#132935 - 2005-02-09 04:33 PM Re: Network Print Mapping
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
HeHe... I did say the code was "untested". Just trying to get him going.
Top
#132936 - 2005-02-09 04:34 PM Re: Network Print Mapping
bestia Offline
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
#132937 - 2005-02-10 02:47 PM Re: Network Print Mapping
maciep Offline
Korg Regular
*****

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

Top
#132938 - 2005-02-10 02:55 PM Re: Network Print Mapping
bestia Offline
Fresh Scripter

Registered: 2004-08-26
Posts: 36
Loc: Guildford, UK
Exuse my Ignorance..How do I do that !?
Top
#132939 - 2005-02-10 03:08 PM Re: Network Print Mapping
maciep Offline
Korg Regular
*****

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

Top
#132940 - 2005-02-10 04:06 PM Re: Network Print Mapping
bestia Offline
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 Offline
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 post
Rgds
Bestia

Top
#132942 - 2005-02-14 01:42 PM Re: Network Print Mapping
bestia Offline
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
#132943 - 2005-02-15 12:44 AM Re: Network Print Mapping
Sealeopard Offline
KiX Master
*****

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

Top
Page 3 of 3 <123


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

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.063 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

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