Page 2 of 2 <12
Topic Options
#165627 - 2006-08-09 09:32 PM Re: Install Printers by Computer Names
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Problem is you can have two or three NIC
Code:

Dim $NIC, $IPAddress
$NIC = 0
While EnumIPInfo($NIC,0,0)
$IPAddress = EnumIPInfo($NIC,0,0)
; Install Printers
$NIC = $NIC + 1
Loop


I want to recommend the IsInSubnet UDF to find in which network the workstation is (Thanks Jens "Sealeopard")
Code:

Select
Case IsInSubnet($IPAddress, '192.168.35.0', '255.255.255.0')
; Do something with printers
Case IsInSubnet($IPAddress, '192.168.36.0', '255.255.255.0')
; Do something with printers
Case 1
; Maybe something else
EndSelect


For Citrix or Terminal Server, I want to recommend wtsmanager.dll
See http://www.kixhelp.com/downloads.htm, the simple COM-wrapper for Terminal Services Manager
Code:

If @TSSESSION
$oWts = CreateObject("WTSManager.Shell")
$IPAddress = $oWts.MyIPAddress
If $IPAddress = ""
; Most probably WTSManager.dll is not registered on this terminal server
Exit 0
EndIf
; Do stuff with printers
EndIf


I hope this helps. I am interested in your solution to install printers for your users.


Edited by Witto (2006-08-09 10:32 PM)

Top
#165628 - 2006-08-09 10:39 PM Re: Install Printers by Computer Names
hieucao Offline
Fresh Scripter

Registered: 2006-08-09
Posts: 18
Gargoyle - your script worked great, but if I use it more than once in the login script, it installs all printers regardless which subnet the ws is logging in from...what gives? I've multiple subnets across the network and the print server is centralized in one subnet...
Top
#165629 - 2006-08-09 10:42 PM Re: Install Printers by Computer Names
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Can you post the script you are using? That would make it much easier for us to see what screws things up, now it's just guessing what goes wrong. Please post it in between code tags so the formatting is preserved.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#165630 - 2006-08-09 10:53 PM Re: Install Printers by Computer Names
hieucao Offline
Fresh Scripter

Registered: 2006-08-09
Posts: 18
Mart - here's the script that I am testing.
Code:

:Domain_Users ; Generic drives for all users
$section=$section+1
If InGroup ("Domain Users")
CLS
AT (10,25) "Mapping Drives...Please Wait"

use I: "\\PPFS\%username%"
use Q: "\\hpserver\hpwin"
EndIf



; Installing printers by workstation name worked great. The same printer was
; also installed in Citrix

;If Not @TSSESSION ; Citrix to use Workstation name
; $ComputerName = @WKSTA
;Else
; $ComputerName = %CLIENTNAME%
;EndIf

;Select
;Case Left($ComputerName,4) = "MVIT" ; Install printers by workstation name
; $ = AddPrinterConnection("\\sharepoint\2FLX4500PS")

;EndSelect



; Testing Printer mappings depending on subnet
; Print server is on subnet 24
; All printers get installed regardless which subnet the workstation is logging in from.

If instr(192.168.24.0, $255.255.255.0)
$ = AddPrinterConnection("\\sharepoint\2FLX8550")
EndIf


If instr(192.168.26.0, $255.255.255.0)
$ = AddPrinterConnection("\\sharepoint\2FLX4500PS")
EndIf


Thanks for everyone's input!


Edited by NTDOC (2006-08-09 11:01 PM)

Top
#165631 - 2006-08-09 11:00 PM Re: Install Printers by Computer Names
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Code:

If instr(@IPADDRESS, "192.168.24.")
; Do stuff
EndIf


Top
#165632 - 2006-08-09 11:07 PM Re: Install Printers by Computer Names
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
also, remember, strings must be inside quotes, ALWAYS.
your ip string is syntastically wrong.

and see how witto does it, that's how you want to do it.

Top
#165633 - 2006-08-09 11:16 PM Re: Install Printers by Computer Names
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Yes if you are hardcoding you subnet then as Witto shows.

My assumption was that there would be more than one subnet and you would use a variable so as to be able to loop through them.

Top
#165634 - 2006-08-09 11:23 PM Re: Install Printers by Computer Names
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, witto's example above does show how to make it work.
but indeed, having a var in there, makes it flexible.

on the other hand, hieu seems to have trouble understanding the concept of vars, so need to start from the basics.

Top
#165635 - 2006-08-09 11:28 PM Re: Install Printers by Computer Names
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I presume if you are in a different subnet you would want PrinterB or PrinterC
Code:

Select
Case instr(@IPADDRESS, "192.168.24.")
$ = AddPrinterConnection("\\Server\PrinterA")
Case instr(@IPADDRESS, "192.168.25.")
$ = AddPrinterConnection("\\Server\PrinterB")
Case instr(@IPADDRESS, "192.168.26.")
$ = AddPrinterConnection("\\Server\PrinterC")
Case 1
; Something Else
EndIf


And what if you have a fixed and a wireless NIC in your portable...

Top
#165636 - 2006-08-09 11:44 PM Re: Install Printers by Computer Names
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Uhm Witto....

Select .... EndIf ?

Top
#165637 - 2006-08-09 11:47 PM Re: Install Printers by Computer Names
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
hieucao :
From the manual -
Quote:


InStr( )

Action: Scans a string (from left to right) for the presence of a second string.

Syntax: INSTR ("string1", "string2")

Parameters: String1

The string to search in.

String2

The string to search for.

Returns: ?
Offset of the first character of string2 found in string1

0
String2 not present in string1



Top
#165638 - 2006-08-10 12:08 AM Re: Install Printers by Computer Names
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Whoops, EndSelect
I think @IPADDRESS does not exist. Make it @IPADDRESS0 or @IPADDRESS1 or @IPADDRESS2
But again, what if you have 2 or 3 or more NICs in your computer (fixed, wireless, other), what will @IPADDRESSx return, and @IPADDRESS just goes from 0 to 2
I would prefer to loop all NICs with EnumIPInfo.
I also think my lookup is wrong as @IPADDRESS0 returns something like "192.168. 1. 5"
Code:

instr(@IPADDRESS0, "192.168. 24.")



Edited by Witto (2006-08-10 12:16 AM)

Top
#165639 - 2006-08-10 12:13 AM Re: Install Printers by Computer Names
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
For you and I yes.... But as Jooel reminded us, hieucao, is a noob, and we may be overcomplicating things.
Top
#165640 - 2006-08-10 12:29 AM Re: Install Printers by Computer Names
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You are right. hieucao is an upcoming programmer. Just stick to the KISS principle (keep it simple and stupid). Most important is to have working code. Afterwards, everybody learns and starts to make things better.
Top
#165641 - 2006-08-10 12:35 AM Re: Install Printers by Computer Names
hieucao Offline
Fresh Scripter

Registered: 2006-08-09
Posts: 18
thanks all for providing the feedback. I'll re-read the manual and try all of your suggestions! You guys are awesome!
Thanks!

Top
#165642 - 2006-08-10 02:04 AM Re: Install Printers by Computer Names
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Removes the blank spaces in the IP Address

Code:
Dim $IP
$IP = Join(Split(@IPADDRESS0," "),'')
If Instr($IP,'192.168.24.')


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 1172 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.074 seconds in which 0.03 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