Page 2 of 2 <12
Topic Options
#183498 - 2007-12-11 07:03 PM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Witto Offline
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 Offline
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
\:\)

 Code:
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
#183512 - 2007-12-12 12:55 AM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Might I suggest putting your shell commands inside the if/endif. The way you have it now could lead to some unusual/unexpected results.
Top
#183513 - 2007-12-12 01:17 AM Re: Install Printers using IP?? Is it possible [Re: Allen]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
SHELL "$cmd"

No need for quotes.

SHELL $cmd
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#183515 - 2007-12-12 08:40 AM Re: Install Printers using IP?? Is it possible [Re: rhunton]
Allen Administrator Online   shocked
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:

 Code:
$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
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.064 seconds in which 0.034 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