Page 1 of 1 1
Topic Options
#6436 - 2001-01-23 06:53 AM Changing printer share names
Anonymous
Unregistered


Does anyone have any suggestions for the best way to change printer share names on a network with Windows 95/98 clients as well as NT Workstations?

The share name doesn't affect the NT workstations one bit. However, it does affect Windows 95/98. Is there an alternative to having to reinstall all of the printers manually on each workstation?

I guess I've come to "expect" that there's a kixtart script for most things like this! :-)

Top
#6437 - 2001-01-23 08:25 PM Re: Changing printer share names
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
If you want to change the sharenames via your login script,
You could use a script something like this:

Make an ini-file in your netlogon share, containing the old sharename and the new sharename

Contents of PrtShare.ini:

[Status]
Level=1

[Change]
; Move to New server with new sharename
\\OldServer\OldShare=\\NewServer\NewShare

; Move to new server, same sharename
\\OldServer\OldShare=\\NewServer\OldShare

; Change sharename on current printserver
\\OldServer\OldShare=\\OldServer\NewShare

;---End of PrtShare.ini

The Section: [Status] is used for checking if the printershares have been changed for current user.
If you want to use this option, you have to increase the value for Level everytime you make changes
in the [Change] section


Script: ChangeShare.kix

code:
$IniFile = $LServer + "\NetLogon\PrtShare.ini"

; Check if change has been done for current user
$IniLevel = ReadProfileString("$IniFile", "Status", "Level")
$UserLevel = ReadValue("HKEY_CURRENT_USER\Software\Corporate\Printers", "Level")
If $IniLevel = $UserLevel
Return ; Exit script, printers updated for current user
EndIf
; End - Check if change has been done for current user

If @InWin=1 ; NT
$ChgSub = "ChgNt"
Else
$ChgSub = "Chg9x"
EndIf

$OldShares = ReadProfileString("$IniFile", "Change", "")
$Pos = InStr($OldShares, Chr(10))
While $Pos > 0
$OldShare = SubStr($OldShares, 1, $Pos - 1)
$OldShares = SubStr($OldShares, $Pos + 1, Len($OldShares) - $Pos)
$NewShare = ReadProfileString("$IniFile", "Change", "$OldShare")
GoSub $ChgSub
$Pos = InStr($OldShares, Chr(10))
Loop

; Register that change has been done for current user
$Err = AddKey("HKEY_CURRENT_USER\Software\Corporate")
$Err = AddKey("HKEY_CURRENT_USER\Software\Corporate\Printers")
$Err = WriteValue("HKEY_CURRENT_USER\Software\Corporate\Printers", "Level", "$IniLevel", "REG_SZ")

Return


; *** SUB ***
:ChgNt
$Err = DelPrinterConnection("$OldShare")
If $Err = 0 ; Old share found and deleted, add new share
$Err = AddPrinterConnection("$NewShare")
EndIf

Return


; *** SUB ***
:Chg9x
$Index = 0
$KeyName = EnumKey("HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers", $Index)
While @Error = 0
$ActShare = ReadValue("HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers\" + $KeyName, "Port")
If $ActShare = $OldShare
$Err = WriteValue("HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers\" + $KeyName, "Port", "$NewShare", "REG_SZ")
EndIf
$Index = $Index + 1
$KeyName = EnumKey("HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers", $Index)
Loop

Return

One word of PRECAUTION: Some Win9x drivers also keeps the sharename on binary form in the value:
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers\PrinterName\Default DevMode"
I have observed this for Canon and Minolta copiers when installed as printers.
Check out, if this goes for any of your Win9x drivers, if it does DO NOT use this script.

I have found no problems with HP and Kyocera printers, and i have seen a lot of different models from these two manufacturers.
But if you want to make sure, read the regitry with Regedit.exe and browse the value:
"HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Print\Printers\PrinterName\Default DevMode"

The reason for spelling this out is that i have experinced a lot of crashes on Win9x machines using Minolta and Canon copiers as printers (One out of ten times when printing, printwieving and changing page setup) after i had changed the port with a script like this. I Do use a form of this script AND i don't have a special anomocity for Canon and Minolta, it is just examples of situations where you shouldn't try to change the registry, because there is other 'hidden' values.

Erik

[This message has been edited by kholm (edited 25 January 2001).]

Top
#6438 - 2001-01-24 12:06 AM Re: Changing printer share names
Anonymous
Unregistered


Erik,

Thank you very very much for this script and for your detailed reply.

Most of the printers are HPs, with one Kyocera and one Epson. Hopefully this means that most if not all of the printers can be changed using a script!

One question I did have - is there a way to change the script so that if a user doesn't use all of the printers that are on the network, they won't be added in? The way I read the script is that for each printer in prtshare.ini the script will attempt to delete the old share name (even if it doesn't exist) and then add in the new one.

I had a go at using an If statement in place of While $Pos > 0 to make the substitution only for existing printers but failed dismally!

[This message has been edited by mteal (edited 24 January 2001).]

Top
#6439 - 2001-01-25 02:04 AM Re: Changing printer share names
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
I have changed the original script in this post after mteal contacted me via E-mail and pointed out that printers were always added for NT-systems even if they didn't exist as the old share.

Added update control.

Erik

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1821 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.11 seconds in which 0.09 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