|
|
|||||||
I have moved all of our printers from our old print server cmi-25 to our new print server nsfcmi-4. We are currently still using the old server but i want to repoint everyone to the new server by just changing the servername on the current mapping. The share names are all still the same but the server has changed.... For example \\cmi-25\HP_3600 is now \\nsfcmi-4\HP_3600 I found this script below but i keep getting an error on line 17 saying undefined variable [$PriMapState]! Code: If NOT @LOGONMODE Break On Else Break Off EndIf Dim $SO $SO=SetOption("Explicit", "ON") $SO=SetOption("NoMacrosInStrings", "ON") $SO=SetOption("NoVarsInStrings", "ON") $SO=SetOption("WrapAtEOL", "ON") Dim $OldServer, $NewServer, $ArrPtrs, $Ptr, $PtrMapState, $NUL $OldServer = "\\cmi-25" $NewServer = "\\nsfcmi-4" $ArrPtrs = Split("Printer1,Printer2,Printer3",",") For Each $Ptr In $ArrPtrs $PtrMapState = $PriMapState("\\" + $OldServer + "\" + $Ptr) If 0 < $PtrMapState $NUL = AddPrinterConnection("\\" + $NewServer + "\" $Ptr) If NOT @ERROR AND 2 = $PtrMapState $NUL = SetDefaultPrinter("\\" + $NewServer + "\" $Ptr) If @ERROR ? "Error setting default Printer Connection " + $Ptr ? "Error " + @ERROR + ": " + @SERROR EndIf Else ? "Error adding Printer Connection " + $Ptr ? "Error " + @ERROR + ": " + @SERROR EndIf If NOT @ERROR $NUL = DelPrinterConnection($Ptr) If @ERROR ? "Error deleting Printer Connection " + $Ptr ? "Error " + @ERROR + ": " + @SERROR EndIf EndIf EndIf Next If anyone can suggest a fix or help that would be great... Thanks..... |
||||||||
|
|
|||||||
Hi nige1979 and Welcome to the board. When you post code please place that code in code tags, here is a link that will help you with that, The Post/Reply Formatting Box and How to use it I think the reason your getting that error is because this script is expecting to have a UDF in it called PriMapState, you can find it here. If you copy it into your script I think your error will go away. |
||||||||
|
|
|||||||
Which bit do i copy and where do i paste it on the script. Sorry not very good with this stuff..... |
||||||||
|
|
|||||||
Sure no worries, you want to copy the entire UDF (User Defined Function) into your script, just like this: Code: If NOT @LOGONMODE Break On Else Break Off EndIf Dim $SO $SO=SetOption("Explicit", "ON") $SO=SetOption("NoMacrosInStrings", "ON") $SO=SetOption("NoVarsInStrings", "ON") $SO=SetOption("WrapAtEOL", "ON") Dim $OldServer, $NewServer, $ArrPtrs, $Ptr, $PtrMapState, $NUL $OldServer = "\\cmi-25" $NewServer = "\\nsfcmi-4" $ArrPtrs = Split("Printer1,Printer2,Printer3",",") For Each $Ptr In $ArrPtrs $PtrMapState = $PriMapState("\\" + $OldServer + "\" + $Ptr) If 0 < $PtrMapState $NUL = AddPrinterConnection("\\" + $NewServer + "\" $Ptr) If NOT @ERROR AND 2 = $PtrMapState $NUL = SetDefaultPrinter("\\" + $NewServer + "\" $Ptr) If @ERROR ? "Error setting default Printer Connection " + $Ptr ? "Error " + @ERROR + ": " + @SERROR EndIf Else ? "Error adding Printer Connection " + $Ptr ? "Error " + @ERROR + ": " + @SERROR EndIf If NOT @ERROR $NUL = DelPrinterConnection($Ptr) If @ERROR ? "Error deleting Printer Connection " + $Ptr ? "Error " + @ERROR + ": " + @SERROR EndIf EndIf EndIf Next ;FUNCTION PriMapState ; ;AUTHOR Lonkero (Jooel.Nieminen@gwspikval.com) ; ;ACTION Checks for existent networkprinter connection ; ;VERSION 1.1.1 ; ;CHANGES 1.1.1 - 01. november 2003 ; Fixed buggie descriped in: ; http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=008079 ; 1.1 - 02. July 2002 ; added support for win9x ; 1.0 - 01. July 2002 ; initial release ; ;SYNTAX PriMapState(PRINTER) ; ;PARAMETERS PRINTER ; to be checked Printer's name ; ;RETURNS 1 if printer connected ; 2 if printer is default ; nothing if not connected ; ;REMARKS code for w9x adapted from BrianTX ; ;DEPENDENCIES none ; ;EXAMPLE ; if not PriMapState('\\server\printer1') ; "printer1 not connected!" ; endif ; ;CODE function PriMapState($_Pri) if @inwin=1 if len(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri)) if split(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_Pri $PriMapState=2 else $PriMapState=1 endif endif else dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers" for $_C=0 to 259 $_C2=enumkey($_Root,$_C) If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri) If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri) $PriMapState = 2 Else $PriMapState = 1 Endif Endif if $_C2=259 $_C=$_C2 endif next endif endfunction |
||||||||
|
|
|||||||
Ok, thanks for your help. I have done this and still get the same error.... anymore ideas people..... |
||||||||
|
|
|||||||
Change Code: $PtrMapState = $PriMapState("\\" + $OldServer + "\" + $Ptr) Code: $PtrMapState = PriMapState("\\" + $OldServer + "\" + $Ptr) Glenn |
||||||||
|
|
|||||||
Wow what a helpful bunch of Moderators you guys are.... That fixed the error in the script but then when i tested the changes were not made by the script. Printers still showing mapped to old server..... Anymore helpful ideas..... |
||||||||
|
|
|||||||
Here's what I used recently:
Just change the "oldprintserver" and "newprintserver" names. Glenn |
||||||||
|
|
|||||||
Tried your new one as below but getting error on line 34 saying undefined variable [$oldPSvr]! Code: ; PrintMigrate - Migrates printers from one server to another ; Glenn Barnas - 2006/04/14 ; ; Enumerates all printers, moving printers mapped on the old server to the new server ; assumes that old and new printer names are the same. The default printer is preserved. ; Only one print server (per pass) can be migrated with this utility ; ; The old and new print servers must be defined below ; ; If the old and new printer names are not the same, or printers are being moved between ; multiple print servers, use PrintMigrate2, which utilizes a lookup table to map the old ; server\printer to new server\printer. PrintMigrate2 utilizes a similar process to ; PrintMigrate, but is slower due to the 1:1 mapping needed. Break On Dim $ Dim $OldPServer, $NewPServer ; old/new print server names Dim $LPKey ; Key where printers are defined Dim $DefPtr ; UNC of default printer Dim $Value ; value read from registry Dim $I ; index pointer Dim $Tag ; flag indicating an error in delete/map process $ = SetOption('Explicit', 'On') $ = SetOption('WrapAtEOL', 'On') $ = SetOption('NoVarsInStrings', 'On') $ = SetOption('NoMacrosInStrings', 'On') ;############################################################## ; Define old & new print servers $OldPSvr = '\\cmi-25' $NewPSvr = '\\nsfcmi-4' ;############################################################## ; define key where printers are defined $LPKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts' ; Get current default printer $DefPtr = ReadValue('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows', 'Device') ; Display the default printer If $DefPtr 'Default printer is ' Split($DefPtr, ',')[0] ? ? Else 'Default printer is not defined.' ? ? EndIf ; Enumerate the printers defined for this user $I = 0 ; set the index to 0 ; get the first registry value $Value = EnumValue($LPKey, $I) While Not @ERROR ; process until an EOD error 'Checking ' $Value $Tag = 0 ; clear the error tag If InStr($Value, $OldPSvr) ; If it references the old server $Printer = Join(Split($Value, $OldPSvr), '') ; get the printer name DelPrinterConnection($Value) ; delete the current printer connection If Not @ERROR ; handle error ' - deleted' Else ' Failed to delete printer!' ? $Tag = 1 EndIf If Not $Tag ; add if delete was successful AddPrinterConnection($NewPSvr + $Printer) If Not @ERROR ', added' Else ' Failed to add printer!' ? $Tag = 1 EndIf If Not $Tag If InStr($DefPtr, $Printer) SetDefaultPrinter($NewPSvr + $Printer) If Not @ERROR ', Set as default' Else ' Failed to set as default printer!' ? EndIf EndIf EndIf ? EndIf Else ' - OK' ? EndIf $I = $I + 1 $Value = EnumValue($LPKey, $I) Loop |
||||||||
|
|
|||||||
Dang - change Code: Dim $OldPServer, $NewPServer ; old/new print server names Code: Dim $OldPSvr, $NewPSvr ; old/new print server names Glenn |
||||||||
|
|
|||||||
Ok, now that goes past that point now but errors on line 65 Code: $DefPtr = ReadValue('HKEY_CURRENT_USER\Software\Microsoft\Windows How do i pause the error on the screen so i can read it before it disappears.... |
||||||||
|
|
|||||||
Run the script from a command line. |
||||||||
|
|
|||||||
See attached file for error output. Seems to start ok as works out default printer and the first few in the list but then fails and doesnt change any of the mapping to point to the new loaction ??? |
||||||||
|
|
|||||||
The default printer is connected locally, just thought i would mention this !?!?!?! |
||||||||
|
|
|||||||
The error is stating that you have not defined [dimmed] the variable $Printer. Code: Dim $Printer |
||||||||
|
|
|||||||
??? ok what does that mean, do i need to enter something somewhere ??? sorry to be such a useless noob.... |
||||||||
|
|
|||||||
Just where the other "Dim" statements are in the script, add the one Gargoyle gave you. |
||||||||
|
|
|||||||
Hooray, it works.... BUT.... it doesnt do all the printers in my list. We have some Rocih printers that do not seem to map over. Is there anything that would stop this working... name length, printer type..... |
||||||||
|
|
|||||||
Right, it seems that it just changes a few printers each time it runs. I ran it again and a few more were changed and then the final time it changed the last few printers.... |
||||||||
|
|
|||||||
I'll take a look - when I ran it, it did not have Explicit defined - thought I caught all the DIMs. As for multiple iterations, that's strange. It only addresses currently mapped printers, and we generally have only 3-4 per computer, so might not have seen that issue. Glenn |
||||||||
|
|
|||||||
Ok it doesnt even do it in batches of 4 !!! i just ran it on a pc that had 4 mapped printers.... the 1st time it changed 2 printers the 2nd time it changed 1 and the 3rd time it changed the last printer..... |
||||||||
|
|
|||||||
OK - I added some printers from our old print server and ran the code. It seems that the index of printers being enumerated from the registry is changing. I updated the code to restart the enumeration each time a change is made and it has successfully moved all 3 printers (of the 7 total) in one pass. My original post is updated. Glenn |
||||||||
|
|
|||||||
Glenn and co, I cannot thank you enough for your help. Works a dream now... Great site and great support and help from the Mods... Keep up the good work.... |
||||||||
|
|
|||||||
Great - thanks for the follow-up! Glenn |