#40935 - 2003-06-06 12:28 AM
Re: Enumerating shared printers
|
smacleanwalker
Lurker
Registered: 2003-06-02
Posts: 2
Loc: Bristol
|
Home this is the script i've written. Requires kixforms but you get the idea.
Lists shared printers from a print server, then a gives user a list box of the printer to select.
The file name-ip.lst is a text file containing SERVERNAME IP Address code:
;----------------------------------------------------------------------------------------------------------------------- ;script c2print.kix ;created Steven Maclean-Walker ;Date created 29 May 2003 ;Last modified ;Overview Allows roaming XP laptops to automatically connect printers in local branches ;Uses Kix32.exe version 4.12 or later ; kixforms.dll version 2.20 or later ; Kixforms.dll requires registering using regsvr32.exe ;-----------------------------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------------------------- ;- Read current default printer device. ;- Finds Branch Server name the current printer is connectted too. ;----------------------------------------------------------------------------------------------------------------------- $CurDefPrn = READVALUE('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows', "Device" ) $Len001 = INSTR("\\",$CurDefPrn) $Len002 = INSTR("\",$CurDefPrn) $Len003 = INSTR(",",$CurDefPrn) $CurDefPrnBrSvr = SUBSTR($CurDefPrn,$Len001-1,$Len002-$Len001-1) $CurDefPrnName = SUBSTR($CurDefPrn,10,8)
;--- Debug Checking --- ? "Current printer - " + $CurDefPrn ? " Printer server - " + $CurDefPrnBrSvr ? ;--- Debug Checking ---
;----------------------------------------------------------------------------------------------------------------------- ;- Reads Machine IP address ;- Tidies up ip address so no blanks are showing ;- appends tidy workstation ip address ;- checks for branch subnet ;- appends branch server .11 ip address (assumes all branch servers are xxx.yyy.zzz.11) ;- N.B Above holds true for all branches bar SL2SVR (Solihull MPU) has 172.20 address ;----------------------------------------------------------------------------------------------------------------------- $WorkIpAdd=SUBSTR(@ipaddress0,1,15)
;--- Debug Checking --- False IP Address $WorkIpAdd=" 10. 11. 2.999" ;--- Debug Checking ---
$TempIpAdd=TRIM(SUBSTR($WorkIpAdd,1,3))+"."+TRIM(SUBSTR($WorkIpAdd,5,3))+"."+TRIM(SUBSTR($WorkIpAdd,9,3)) $CleanWorkIpAdd=$TempIpAdd+"."+TRIM(SUBSTR($WorkIpAdd,13,3)) SELECT CASE SUBSTR($WorkIpAdd,1,4) = " 10." $CleanSrvIpAdd=$TempIpAdd+".11" CASE SUBSTR($WorkIpAdd,1,4) = "172." SELECT CASE SUBSTR($WorkIpAdd,5,4) = " 19." $CleanSrvIpAdd = "172.19.2.51" CASE SUBSTR($WorkIpAdd,5,4) = " 20." $CleanSrvIpAdd = "172.20.2.103" CASE SUBSTR($WorkIpAdd,5,4) = " 23." $CleanSrvIpAdd = "172.23.2.52" CASE 1 ENDSELECT CASE 1 $CleanSrvIpAdd=$CleanWorkIpAdd ENDSELECT
;--- Debug Checking --- ? "Current IP Address - " + $CleanWorkIpAdd ? " IP Address server - " + $CleanSrvIpAdd ? ;--- Debug Checking ---
;----------------------------------------------------------------------------------------------------------------------- ;- Reads name-ip.lst for branch server name from ip address ;- Yes I know you could use WINS / DNS to resolve but this is easier I can tell you. Bridging mutliple domains with no local logonserver ;- name-ip.lst is a text file in format below (no spaces in ip address) ; - ANYSVR www.xxx.yyy.zzz ;----------------------------------------------------------------------------------------------------------------------- IF OPEN(1,"name-ip.lst")=0 $txt1=READLINE(1) $len=LEN($txt1) $str=INSTR($txt1,$CleanSrvIpAdd) WHILE $str < 1 AND @ERROR = 0 $txt1=READLINE(1) $len=LEN($txt1) $str=INSTR($txt1,$CleanSrvIpAdd) LOOP IF @ERROR = -1 ? " -*- END OF FILE name-ip.lst -*- " ENDIF CLOSE(1) ENDIF $SrvNmeLen=INSTR($txt1," ") $LocalSrvName=UCASE(SUBSTR($txt1,1,$SrvNmeLen-1))
;--- Debug Checking --- ? "Current Server code- " + $LocalSrvName ? "Name String Length - " + $SrvNmeLen ;--- Debug Checking ---
;----------------------------------------------------------------------------------------------------------------------- ;- Select printer and prompt user to check printer ;----------------------------------------------------------------------------------------------------------------------- ;IF UCASE($CurDefPrnBrSvr) = UCASE($LocalSrvName) ; $PrnSelect=MESSAGEBOX("Current printer connected is " + $CurDefPrnName + ". Do you want to use this printer?","Current mapped printer",4,4096)
;--- Debug Checking --- ;? "Options selection - " + $PrnSelect ;--- Debug Checking ---
; IF $PrnSelect = 6 ; SETDEFAULTPRINTER ("\\$CurDefPrnBrSvr\$CurDefPrnName") ; QUIT ; ELSE ; GOSUB ChoosePrinter ; ENDIF ;ELSE GOSUB ChoosePrinter ;ENDIF
;----------------------------------------------------------------------------------------------------------------------- ;- ChoosePrinter creates GUI window with current branch printers ;----------------------------------------------------------------------------------------------------------------------- :ChoosePrinter SHELL "CMD /C net view \\$LocalSrvName | findstr Print > c:\temp\BranchPrinters.lst"
$PrintForm = CreateObject("Kixtart.Form") $PrintForm.ClientWidth = 510 $PrintForm.ClientHeight = 200 $PrintForm.FontName = Verdana $PrintForm.FontSize = 10 $PrintForm.Text = "Please select a printer" $PrintForm.Center $PrintForm.Show
IF UCASE($CurDefPrnBrSvr) = UCASE($LocalSrvName) $PrintForm.PrintXY(10,10,"Your current printer is: $CurDefPrnName") ELSE $PrintForm.PrintXY(10,10,"Your default printer is not in this branch") ENDIF $PrintForm.PrintXY(10,30,"Please double click printer name to select")
; $txtinfo = $PrintForm.TextBox ; $txtinfo.Bounds = 50,10,100,25
$PrintList = $PrintForm.ListView() $PrintList.Left = 380 $PrintList.Top = 10 $PrintList.Width = 115 $PrintList.Bottom = $PrintForm.ClientHeight - 10 $PrintList.OnDoubleClick = "Default_Click()" $PrintList.Sorted = 1 $PrintList.MultiSelect = False $PrintList.Gridlines = True $PrintList.View = 3 $PrintList.FullRowSelect = False
$=$PrintList.Columns.Add("Printer Name",100) Load_Click()
WHILE $PrintForm.Visible $= EXECUTE($PrintForm.DoEvents) LOOP Exit 1
Function Default_Click() $PrintList.SetFocus ? "\\"+$LocalSrvName+"\"+$PrintList.FocusedItem.SubItems(0).Text ;DELPRINTERCONNECTION ("\\"+$LocalSrvName+"\"+$PrintList.FocusedItem.SubItems(0).Text) $PrintForm.PrintXY(10,140,"Please wait while printer connection is estabished...") ADDPRINTERCONNECTION ("\\"+$LocalSrvName+"\"+$PrintList.FocusedItem.SubItems(0).Text) $PrintForm.PrintXY(10,160,"Setting default printer... ") SLEEP 1 SETDEFAULTPRINTER ("\\"+$LocalSrvName+"\"+$PrintList.FocusedItem.SubItems(0).Text) $PrintForm.PrintXY(10,180,"connection estabished... ") SLEEP 1 QUIT EndFunction
Function Load_Click() $PrintForm.MousePointer = 11 $PrintForm.Enabled = 0 $PrintForm.BeginUpdate $PrintList.Items.Clear IF OPEN(1,"c:\temp\BranchPrinters.lst")=0 $cnt=0 $txt1=READLINE(1) WHILE @ERROR <> -1 $PrintItemTmp=SUBSTR($txt1,1,8) $PrintItem = $PrintList.Items.Add($PrintItemTmp) ;--- Debug Checking --- ? "Printer in " + $CurDefPrnBrSvr " - " + $PrintItemTmp ;--- Debug Checking --- $cnt = $cnt + 1 $txt1=READLINE(1) LOOP $cntmax = $cnt ;--- Debug Checking --- ? "Number of printers - " + $cntmax ? ;--- Debug Checking --- CLOSE(1) ENDIF $PrintForm.EndUpdate $PrintForm.MousePointer = 0 $PrintForm.Enabled = 1 $PrintList.Setfocus EndFunction RETURN
_________________________
Regards Steve
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|