Page 1 of 1 1
Topic Options
#119863 - 2004-05-20 09:56 AM Move Printer Server
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11611
Loc: CA
Here is an example script to move a users currently mapped printers to a new
print server as defined in a PRINTERS.INI file.

The PriMapState UDF for this example is located here and is a more updated version then this example.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=82672

Code:
; Set our options
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')

; Set $CurrentIP to Global so other functions can use it's value
GLOBAL $CurrentIP

; Assign the returned value of the GetCurrentIP() UDF to $CurrentIP
$CurrentIP=GetCurrentIP()
ResetPrinters()


Function ResetPrinters()
Dim $pmap,$key,$nulp
Select
; Check if the user's IP is a given value and assign the path and file name of the
; INI file that contains the PRINTER listing

Case InStr($CurrentIP, '122.100.120')
$pmap="\\122.100.120.150\common\PRINTERS\PRINTERS.INI"
Case InStr($CurrentIP, '122.100.121')
$pmap="\\122.100.120.150\common\PRINTERS\PRINTERS.INI"
Case InStr($CurrentIP, '124.124.110')
$pmap="\\124.124.110.24\common\PRINTERS\PRINTERS.INI"
Case 1
$pmap="\\122.100.120.150\common\PRINTERS\PRINTERS.INI"
EndSelect
If @INWIN=1
; For each entry in the INI file check if it exist and check if the printer is a default printer
; then add the new printer and remove the old one using the PriMapState UDF.

For Each $key In Split(ReadProfileString($pmap,"PRINTER_MAP",""),chr(10))
If PriMapState($key)
$nulp=AddPrinterConnection(ReadProfileString($pmap,"PRINTER_MAP",$key))
If PriMapState($key)=2
$nulp=SetDefaultPrinter(ReadProfileString($pmap,"PRINTER_MAP",$key))
EndIf
$nulp=DelPrinterConnection($key)
EndIf
Next
EndIf
EndFunction

Function PriMapState($_Pri)
; Check if the Length is greater then blank for the specified registry location
; and if it is then move on to the next If statement which checks if the printer listed is
; a default printer or not.

If Len(ReadValue('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices',$_Pri))
If InStr(ReadValue('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows','Device'),$_Pri)
$PriMapState=2
Else
$PriMapState=1
EndIf
EndIf
EndFunction


; UDF Pings the workstation and puts the value in a text file. Then it reads the text file
; and places the value into $GetCurrentIP

Function GetCurrentIP()
Dim $TempFile, $Line, $cf
$TempFile = '%TEMP%\PING.TXT'
If Exist($TempFile)
Del $TempFile
EndIf
Shell '%COMSPEC% /C PING -n 1 ' + @WKSTA + '>'+$TempFile
If open(1, $TempFile) = 0
$Line = ReadLine(1)
While @ERROR = 0
If InStr($Line,@WKSTA)
$Line = SubStr($Line,InStr($Line,"[")+1)
$GetCurrentIP = SubStr($Line,1,InStr($Line,"]")-1)
EndIf
$Line = ReadLine(1)
Loop
$cf = Close(1)
EndIf
If Exist($TempFile)
Del $TempFile
EndIf
EndFunction


 

EXAMPLE PRINTERS.INI

Code:
[PRINTER_MAP]
\\PS22\PS22_TURK=\\PS09\SP-NORTH-TURK
\\PS22\PS22_DIRK=\\PS09\SP-NORTH-DIRK
\\PS22\PS22_SONET=\\PS09\SP-NORTH-SONET
\\PS22\PS22_KLONDIKE=\\PS09\SP-NORTH-KLONDIKE


Top
#187177 - 2008-04-22 10:30 PM Re: Move Printer Server Fixed [Re: ghangis]
SnoopDuJour Offline
Just in Town

Registered: 2008-04-22
Posts: 3
I added this to the bottom of my script. This fixed the problem printer + kept the defalt printer.

-----------------------------------------
Function PriMapState($_Pri)
If Len(ReadValue('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices',$_Pri))
If InStr(ReadValue('HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows','Device'),$_Pri)
$PriMapState=2
Else
$PriMapState=1
EndIf
EndIf
EndFunction
------------------

Top
Page 1 of 1 1


Moderator:  NTDOC, ShaneEP, Mart, Radimus, Glenn Barnas, Jochen, Allen 
Hop to:
Shout Box

Who's Online
0 registered and 290 anonymous users online.
Newest Members
Praveer, Ollero, rayyo, Foxlicht, DonChild
17742 Registered Users

Generated in 0.029 seconds in which 0.011 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