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