Page 1 of 1 1
Topic Options
#187369 - 2008-04-28 05:19 PM migrating print server
ghangis Offline
Just in Town

Registered: 2008-04-21
Posts: 4
Loc: canada
under request from NTDOC, I am starting this thread to continue a conversation from another thread re: migrating shared printers from one server to another...

I've been trying to get the PRIMAPSTATE UDF to work with no success. if someone can help me understand how to incorporate a UDF into my existing kix script. what I need to do is as follows...

if a user is mapped to \\serverA\printer1 I need the script to map \\serverB\printer1 then delete \\serverA\printer1. the only change is with the path as the share name is the same.

P.S. my apologies for "hijacking" the thread I previously posted on...

..help

Top
#187370 - 2008-04-28 07:01 PM Re: migrating print server [Re: ghangis]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
The easiest way is just to copy and paste the function's code into your script somewhere (I prefer the end of the script, but it technically doesn't matter). KiXtart parses the script when it is run, and anything inside Function...EndFunction blocks gets treated as if it's a built-in KiXtart function.
Top
#187372 - 2008-04-28 08:16 PM Re: migrating print server [Re: ghangis]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
A quick and dirty one. I'm sure that are other (and shorter) ways of doing this but the script below should work. There are lots of comments in the code so you can see what each line does.

 Code:
Break on

;Enumerate the current (old) printer connections.
$printers = ArrayEnumKey("HKEY_CURRENT_USER\Printers\Connections")

;Get the default printer.
;Why? See If - Endif statement below.
$defaultprinter = GetDefaultPrinter()

;Split the default printername on \.
;This makes an array you can reference to an element later.
$defaultprinter = Split($defaultprinter, "\")

;Get just the default printer name. Strip off the server name.
;Get the contents of the highest element in the array created above.
$defaultprintername = $defaultprinter[Ubound($defaultprinter)]

;Do stuff for each printer found.
For Each $printer in $printers
	;
	;Split the key name on ,.
	;This makes an array you can reference to an element later.
	$printersplit = Split($printer, ",")
	;
	;Get just the printer name. No server, no comma's.
	;Get the contents of the highest element in the array created above.
	$printername = $printersplit[Ubound($printersplit)]
	;
	;Delete the old printer.
	$rc = DelKey("HKEY_CURRENT_USER\Printers\Connections\" + $printer)
	;
	;Connect the same printer but with the new server name.
	$rc = AddPrinterConnection("\\newserver\" + $printername)
	;
	;If the printer being added is the same as the old default printer then
	;set the new printer as default.
	If $printername = $defaultprintername
		;Set the default printer.
		$rc = SetDefaultPrinter("\\newserver\" + $printername)
	EndIf
Next


;=-=-=-=--= DO NOT MODIFY ANYTHING BELOW THIS LINE =-=-=-=--=
;=-=-=-=--= BELOW ARE UDF'S. THEY COME READY MADE. =-=-=-=--=


;HKEY_CURRENT_USER\Printers\Connections\,,jupiter,RTD-PRN003

;NAME          ArrayEnumKey
;
;ACTION        Creates an array of names of the subkeys contained in a registry key or subkey
;
;AUTHOR        Jens Meyer (sealeopard@usa.net)
;
;VERSION       1.2 (added error codes)
;              1.1
;
;DATE CREATED  2001/12/05
;
;DATE MODIFIED 2003/05/17
;
;KIXTART       4.12+
;
;SYNTAX        ARRAYENUMKEY($subkey)
;
;PARAMETERS    SUBKEY
;              Required string containing the key or subkey for which the subkeys will be enumerated
;
;RETURNS       Array containing the subkeys
;
;REMARKS       none
;
;DEPENDENCIES  none
;
;EXAMPLE       $retcode=arrayenumkey('HKEY_USERS')
;
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000064
;
Function arrayenumkey($regsubkey)
  Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray

  If NOT KeyExist($regsubkey)
    Exit 87
  EndIf

  $subkeycounter=0
  Do
    $currentsubkey=EnumKey($regsubkey,$subkeycounter)
    If NOT @ERROR
      ReDim preserve $subkeyarray[$subkeycounter]
      $subkeyarray[$subkeycounter]=$currentsubkey
      $subkeycounter=$subkeycounter+1
    EndIf
  Until @ERROR

  $arrayenumkey=$subkeyarray
  Exit 0
EndFunction

;FUNCTION         GetDefaultPrinter()
;
;AUTHOR           Jochen Polster (jochenDOTpolsterATgmxDOTnet)
;
;VERSION          1.0
;
;VERSION HISTORY  1.0 2004/04/28 Initial release
;
;ACTION           Retrieves the current default Printer
;
;SYNTAX           GetDefaultPrinter()
;
;PARAMETERS       none
;
;REMARKS          won't work with 9x OS
;
;RETURNS          The current Users default Printer
;
;DEPENDENCIES     None !
;
;EXAMPLES         $default = GetDefaultPrinter

Function GetDefaultPrinter()
    $GetDefaultPrinter = Join(Split(ReadValue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187376 - 2008-04-29 03:08 AM Re: migrating print server [Re: ghangis]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Don't forget that printer NAMES and SHARE NAME should match if they don't then that can cause problems.
Top
#187378 - 2008-04-29 03:39 PM Re: migrating print server [Re: NTDOC]
ghangis Offline
Just in Town

Registered: 2008-04-21
Posts: 4
Loc: canada
Mart, your script is outstanding!!!

Thank you all very much for you patience.

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 515 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.051 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

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