#183498 - 2007-12-11 07:03 PM
Re: Install Printers using IP?? Is it possible
[Re: rhunton]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
How can you be so sure that you only have one NIC with an IP Address bound to it? You can loop through all the network adapters.
;************************************************************************* ; Script Name: LoopNICs ; Author: Wim Rotty ; Date: 11/12/2007 ; Description: Loop all network adapters with IP Address ;************************************************************************* ;Script Options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit", "On") $RC = SetOption("NoMacrosInStrings", "On") $RC = SetOption("NoVarsInStrings", "On") If @SCRIPTEXE = "KIX32.EXE" $RC = SetOption("WrapAtEOL", "On") EndIf
;Declare variables Dim $i, $IPAddress
;Initialize variables $i = 0
;Code $IPAddress = EnumIPInfo($i,0,1) While Not @ERROR If Not $IPAddress = "0.0.0.0" "IP Adderss: " $IPAddress ? "Subnet Mask: " EnumIPInfo($i,1,1) ? "Adapter Description: " EnumIPInfo($i,2,1) ? "Default Gateway: " EnumIPInfo($i,3,1) ? ? EndIf $i = $i + 1 $IPAddress = EnumIPInfo($i,0,1) Loop ;Personal UDF Section
;UDF Section |
|
|
Top
|
|
|
|
#183509 - 2007-12-12 12:06 AM
Re: Install Printers using IP?? Is it possible
[Re: Witto]
|
rhunton
Fresh Scripter
Registered: 2007-12-08
Posts: 11
Loc: York, United Kingdom
|
Finally found / developed some code that deletes local printers. Thanks for the script by Allen Powell (Al_Po)
Please excuse my crude development but it works and thats all that matters 
Function PrinterExist($PrinterName,optional $remotepc)
dim $service,$printer,$printers
$printerexist=0
if $remotepc=""
$remotepc='\\'+ @wksta
else
if not left($remotepc,2)="\\"
$remotepc='\\' + $remotepc
endif
endif
$Service=GetObject("winmgmts:{impersonationLevel=impersonate}!" + $remotepc +"\root\cimv2")
if not @error=0
exit @error
endif
$Printers=$service.execquery ('select * from Win32_Printer')
for each $printer in $printers
if ucase($printername)=ucase($printer.name)
$printerexist=1
endif
if left($printer.name,2)="\\"
if ucase($printername)=ucase(split(substr($printer.name,3),"\")[1] + " on " + split(substr($printer.name,3),"\")[0])
$printerexist=1
endif
endif
next
endfunction
dim $printer1
dim $printer2
$printer1 = "1" ;Deployed Printer Names
$printer2 = "2" ;Deployed Printer Names
if printerexist($printer1)
$cmd = 'rundll32 printui.dll,PrintUIEntry /dl /n "$printer1"'
endif
SHELL "$cmd"
if printerexist($printer2)
$cmd = 'rundll32 printui.dll,PrintUIEntry /dl /n "$printer2"'
endif
SHELL "$cmd"
|
|
Top
|
|
|
|
#183515 - 2007-12-12 08:40 AM
Re: Install Printers using IP?? Is it possible
[Re: rhunton]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
I have not tested this, but this would be the way I go at it:
$printer1="HP xyz"
if printerexist($printer1)
$RC=RemovePrinter($printer1)
endif
function RemovePrinter($PrinterName)
shell='rundll32 printui.dll,PrintUIEntry /dl /n "' + $printername + '"'
if @error
$RemovePrinter=1
exit @error
else
$RemovePrinter=0
endif
endfunction
When I get a few minutes, I will test this and post to UDFs. It's amazing, as much as people ask how to add printers, no one that I remember, has ever asked how to remove them.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1662 anonymous users online.
|
|
|