rhunton
(Fresh Scripter)
2007-12-08 02:18 PM
Install Printers using IP?? Is it possible

Hi All,
I am a complete n00b to kixtart scripting.
I am not sure where to ask this question or if it is at all possible!!
This is what I have at the moment.

Dim $defaultgw
$defaultgw = EnumIPInfo($NIC,3)
If $defaultgw == '192.168.1.1'
"Your Default Gateway is: " + EnumIPInfo($NIC,3)
USE K: '\\servername\servershare'
else if $defaultgw == '192.168.2.1'
USE L: '\\servername\servershare'

Now the problem I have now is I would like kix to install a printer on the detected network subnet.
This would involve creating a new TCP/IP printer port and then installing the drivers.
eg if 192.168.1.1 was detected it would install 192.168.1.2

Has anyone got any ideas on how to do this?
The script would be rolled out to around 400 desktops and 350 laptops if it is possible!!!

Thanks for your help


Les
(KiX Master)
2007-12-08 04:00 PM
Re: Install Printers using IP?? Is it possible

750 computers all doing unmanaged printing! Why? Why not manage them with print servers?

AllenAdministrator
(KiX Supporter)
2007-12-08 04:23 PM
Re: Install Printers using IP?? Is it possible

Addprinterconnection() is the way to connect to NT Based print servers, and in most cases is the preferred way of doing things. Once the printer is setup on the server correctly, and then shared, it is simply a matter of using addprinterconnection. The configuration of the printer, and its drivers come over when you add the connection. It is built into kix. See the manual for further explanation.

Addprinter()is a User Defined Function. It provides a way to add a Local printer (including IP, LPT, COM) to a workstation. To install, it requires the print drivers be available, either on the pc or on the network. The user installing/running the script must be an Administrator of the PC. You also have to define the port, the name, amongst other settings. Addprinter() can be found here: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84165#Post84165


rhunton
(Fresh Scripter)
2007-12-08 04:43 PM
Re: Install Printers using IP?? Is it possible

Thanks for the help; I will give that a stab.
I maybe should have said the computers are distributed throughout the UK. We have several regional offices and about 50 building sites all connected back with ADSL.
Depending on the site we may only have 2 PC’s to 1 printer others can have 15 PC’s to 1 printer.
I will work on it and the bigger sites may just warrant a print servers

Cheers Guys


rhunton
(Fresh Scripter)
2007-12-08 11:44 PM
Re: Install Printers using IP?? Is it possible

Help with AddPrinter() - Add IP,LPT, or COM Printers.

I have been playing about with the script that you advised me to use but am unable to make any use of it.

The part that I am finding hard to understand is when a line starts with a; - does that mean its commented out. It does in VB?
Also, in the script where do you declare all the information? Is it all under the parameters section that I though was commented out?


Gargoyle
(MM club member)
2007-12-09 12:22 AM
Re: Install Printers using IP?? Is it possible

Yes a ; is a comment mark - as for the parameters those are what are passed into the UDF

In this particular case
AddPrinter(192.168.0.100,"HP400M","C:\Drivers\HP.INF","Secretary Pool",,1)

Would add a printer on port 192.168.0.100 The Inf file would have the printer listed in it as HP400M and the INF file is located at C:\Drivers, the description on the printer is Secretary Pool, it will be installed on the local machine and will be set as default.

Does this help?


rhunton
(Fresh Scripter)
2007-12-09 11:01 AM
Re: Install Printers using IP?? Is it possible

Hi, thanks for the reply.
I just need one last bit of help please.

When you are defining the informtion, how do you format it?
for example take $port =
Does the information have to be contained between the brackets or do you just type 192.168.1.1, "192.168.1.1", (192.168.1.1), ("192.168.1.1")

I think once I know the answer to this it should be pretty stright forward

;Parameters:
; $Port = "192.168.1.1"
; IPAddress(RAW) (xxx.xxx.xxx.xxx)
; IPAddress(LPR) (xxx.xxx.xxx.xxx:LPRQueueName)
; LPT (LPT1:)
; COM (COM1:)
; PrintServer (\\server\printer)

Thanks again


Les
(KiX Master)
2007-12-09 03:44 PM
Re: Install Printers using IP?? Is it possible

Don't modify anything inside the UDF. Pass them as parms. All strings should be quoted. Allen provided four examples!

rhunton
(Fresh Scripter)
2007-12-09 05:03 PM
Re: Install Printers using IP?? Is it possible

Thanks for the help guys. All working now!!

Is it possible to skip a printer install if it is currently installed?
When I run the script I end up with printer1, printer1 (copy 1), printer1 (copy2) etc.

Thanks


AllenAdministrator
(KiX Supporter)
2007-12-09 05:08 PM
Re: Install Printers using IP?? Is it possible

Yup... See PrinterExist() http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84400#Post84400

rhunton
(Fresh Scripter)
2007-12-09 08:56 PM
Re: Install Printers using IP?? Is it possible

Hi All,
On a seperate note how would I do the following?
I would like to pass the result of EnumIPInfo($NIC,3) into a variable.

This is what I have at the moment

Dim $defaultgw
$defaultgw = EnumIPInfo($NIC,3)

If $defaultgw == '192.168.1.1'
"Your Default Gateway is:" + EnumIPInfo($NIC,3)
call "another kix script"
else
endif
If $defaultgw == '192.168.2.1'
else
endif

Have I got the part correct about passing the result of EnumIPInfo($NIC,3) into the variable?

Thanks


Les
(KiX Master)
2007-12-09 09:35 PM
Re: Install Printers using IP?? Is it possible

What is $NIC, why are you forcing case with ==, and why the empty ELSE sections?

rhunton
(Fresh Scripter)
2007-12-09 10:19 PM
Re: Install Printers using IP?? Is it possible

Hi Les,
The $NIC is querying my network card information.

The idea to the script:
When I get a user plugs into one of our remote networks for the first it will install the printers for that network on the users pc.

I just remember from my Visual Basic days at college that == worked and I just gave it a try - i am guessing that = will work just as well.

Will I get away without putting else statements in the code?

I have got the code running now and thanks to the scripts from Allen all is working great.

I have no doubt that I will run into problems in the future so will be in contact again.

Thanks All

Rob


Les
(KiX Master)
2007-12-09 10:40 PM
Re: Install Printers using IP?? Is it possible

I don't see where you set any value to $NIC. How and where do you determine what value to assign to $NIC?

In KiX, == forces a case sensitive =.

ELSE is not needed if there is no ELSE condition.


rhunton
(Fresh Scripter)
2007-12-09 10:56 PM
Re: Install Printers using IP?? Is it possible

The EnumIPInfo($NIC,3) is calling information from my network card. IE Static address or DHCP Address
From what I read;
EnumIPInfo($NIC,1) = IP Address
EnumIPInfo($NIC,2) = Subnet Mask
EnumIPInfo($NIC,3) = Default Gate

I just googled the problem it turned up that code.

I have now got to implement it in an Active directory to see what the result is.

Hope the above is use to other people.


Les
(KiX Master)
2007-12-09 11:09 PM
Re: Install Printers using IP?? Is it possible

Still, I don't see where you assign any value to $NIC! You should not rely on blind faith that $NIC will somehow magically have a suitable value.

Les
(KiX Master)
2007-12-09 11:28 PM
Re: Install Printers using IP?? Is it possible

You take the time to Dim $defaultgw but then use an undefined var $NIC.

Essentially, your code is:
$defaultgw = EnumIPInfo(,3)
or:
$defaultgw = EnumIPInfo(0,3)

It is only by the good grace of Ruud and his forgiving code that lets you get away with it. What if 0 isn't the NIC index you need? Your code is too optimistic.


rhunton
(Fresh Scripter)
2007-12-10 04:37 PM
Re: Install Printers using IP?? Is it possible

Hi Les,
Thanks for that.
I realized that when you have multiple network cards like in a laptop you need to query all of them to see which is connected.
The script now runs:

 Code:
Dim $defaultgw0
Dim $defaultgw1
Dim $defaultgw2
$defaultgw0 = EnumIPInfo(0,3)
$defaultgw1 = EnumIPInfo(1,3)
$defaultgw2 = EnumIPInfo(2,3)

If $defaultgw0 = '192.168.1.1' or $defaultgw1 ='192.168.1.1' or $defaultgw2 ='192.168.1.1'
call file.kix


Works a treat now and it works with laptops and desktop.

I see where you were coming from now.


Thanks!!


Mart
(KiX Supporter)
2007-12-10 06:26 PM
Re: Install Printers using IP?? Is it possible

There is no need for the double =. Like Les already said = = does a case sensitive =. An IP address has no upper or lower case so = will work just great.

Can you use code tags the next time you post some code? It is much easier to read a script that way especially when it is a larger script then you have now because the formatting gets preserved


rhunton
(Fresh Scripter)
2007-12-11 04:36 PM
Re: Install Printers using IP?? Is it possible

Hi All,
I have been looking at the DelPrinterConnection() but it looks like it will not remove the local printers.

I can get rid of the network ones - thats great but ideally need a scipt that will work with local printers as well.

I know that this command works:
 Code:
if printerexist("OKI B4350 (Test Printer1)")
  run '%COMSPEC% /C START rundll32 printui.dll,PrintUIEntry /dl  /n "OKI B4350 (Test Printer1)"
endif

but would like to keep all the kix scripts kixy not having to call cmd commands in the middle of scripts.

Also if I use the above code I get windows shouting at me saying that it is not installed or has been removed.

Thanks


Witto
(MM club member)
2007-12-11 07:03 PM
Re: Install Printers using IP?? Is it possible

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


rhunton
(Fresh Scripter)
2007-12-12 12:06 AM
Re: Install Printers using IP?? Is it possible

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"


AllenAdministrator
(KiX Supporter)
2007-12-12 12:55 AM
Re: Install Printers using IP?? Is it possible

Might I suggest putting your shell commands inside the if/endif. The way you have it now could lead to some unusual/unexpected results.

Les
(KiX Master)
2007-12-12 01:17 AM
Re: Install Printers using IP?? Is it possible

SHELL "$cmd"

No need for quotes.

SHELL $cmd


AllenAdministrator
(KiX Supporter)
2007-12-12 08:40 AM
Re: Install Printers using IP?? Is it possible

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.