Page 1 of 2 12>
Topic Options
#39087 - 2003-04-12 12:38 AM Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
New to Kix and from a Shell scripting background.
I have hundreds of printers to add using kix scripts and instead of consecutive if statements i would like to use a for loop. My problem is now A i need to get a list of groups the user is a member of, and B need to be able to querry a line in a config file for fields. That way i can execute the for loop to querry a printer file for names matching groups and install the printer...
Any help would be gr8!
tnx

Top
#39088 - 2003-04-12 12:41 AM Re: Adding Printer Mare
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lots of samples around the board...

mm... think there is even user defined function doing almost exactly what you want.

anyway, if you specify little more specific what the config file looks like...
kixtart version you are using if not 4.12 or never...
etc...

might get some pointers more [Wink]
_________________________
!

download KiXnet

Top
#39089 - 2003-04-11 03:32 PM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
thanks the exe is version 3,62,0,0
I get the
if ingroup ("Blob")=1
if setdefaultprinter(\\server1\blobprn")=0
endif
but i need to extract groups from logged in user, check a config file for matching groups and then add the printer thats in the next column in the config file. (still stuck in grep, sed and awk mode sorry!)
so a for each loop could be run against the users groups to find the matching one and then make default

P.S. Any good docs on Kix?

Top
#39090 - 2003-04-11 03:35 PM Re: Adding Printer Mare
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Arrange your printer and groups in .INI files, see for example UnmapPrinters() - Removes mapped printers not listed in an .INI file for the .INI file format.

[ 11. April 2003, 16:17: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#39091 - 2003-04-11 04:14 PM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
OK, so how do i extract a list of groups a user is a member of? Is the a way of executing NT commands within Kix?
Still looking for a good Document on Kix!

Top
#39092 - 2003-04-11 04:19 PM Re: Adding Printer Mare
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I guess a 'good document' on KiXtart would be the KiXtart Manual that comes with KiXtart? And the UDF Forum contains a lot of helpful information, too.

INGROUP() tests for group membership of as user.

Might be time to actually RTFM.
_________________________
There are two types of vessels, submarines and targets.

Top
#39093 - 2003-04-11 04:58 PM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
RTFQ!
can you get a list of Groups the user is in, was my question?
Not in the Manual! that i can see.
I dont want to ask what group he's in, I want a list of them like showgrps on reskit. I am trying to avoid constant if statements and just create a loop with a config file. If you have another suggestion go ahead. I already have groups created for printers, now i need to script it to make the default one.
I have just started kix today and the document aint exactly "in a nutshell"
Thanks for the help!

Top
#39094 - 2003-04-11 05:00 PM Re: Adding Printer Mare
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jens,
quote:
thanks the exe is version 3,62,0,0

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

Top
#39095 - 2003-04-11 05:03 PM Re: Adding Printer Mare
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jac,
Borrowing from the manual...
quote:
EnumGroup()



Action: Enumerates the global groups of which the current user is a member.
Syntax: ENUMGROUP (Index)
Parameters: Index
- A numeric value representing the group whose name you want to discover (where 0 is the first subkey).
Returns: String Global group name
Error code Function failed.



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

Top
#39096 - 2003-04-11 05:16 PM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
DOH!
The School of hard knocks really is a mean teacher, the wood is now much clearer from the tree's thnx.

PS. Go easy i'm a kix newbie

Top
#39097 - 2003-04-11 05:34 PM Re: Adding Printer Mare
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
[Big Grin]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#39098 - 2003-04-12 12:14 AM Re: Adding Printer Mare
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Jac:

Did you actually look at the .INI file structure I pointed you to? That one associates printers with groups. One the reads the printers into an array, then for each printer, the script checks whether the user in in the groups associated with the printer. That's about 10 lines of code in KiXtart 4.x

Also, might be time to upgrade to KiXtart 4.x in order to take advantage of new features like UDFs.
_________________________
There are two types of vessels, submarines and targets.

Top
#39099 - 2003-04-15 03:34 PM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
Thanx but not an option at present due to every printer having its own group.

Question
If $ Group returns my group within a loop to get them all. How would i go about appending them to a var to make an array. Along the lines of
$Groups = $Groups + $Group.
Used Enum to get group in a do until 0 loop to get them all now i need to either get the list of them all in an array! am i confused or what. Or should i output them to a temp file, but then i'd need a command to search for occurances.
[Confused]

Top
#39100 - 2003-04-15 03:53 PM Re: Adding Printer Mare
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
When you say that every printer has it's own group do you mean that you are defining the printers that a user has by group membership?

For example, membership of groups "Printer: abc" and "Printer: def" will map printers "abc" and "def"?

Top
#39101 - 2003-04-16 10:07 AM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
Exactly that!
eg
Group: Printer HP1
Printer: HP1

current an if in statement does all the printer 1000's the scripts are huge. i want to get the groups id the printer group and assign a printer from a file listing all the printers.

I was thinking my do until could be done till the group contained the word printer and then strip "printer " search the txt file for hp1 and assign as default. This maybe a bit much for kixstart or may be easy. Dunno which yet.

eg. printer.txt
//server1/printer HP1

Top
#39102 - 2003-04-16 10:51 AM Re: Adding Printer Mare
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Easy as a very easy thing indeed.

Final question, are the printers all attached to the same print server?

If so you are in for a real treat.

Here is some sample code which assumes:
1) The print server is static.
2) The group names areformal and consistant.
3) So are the printer names.

Given that your print server is "\\MyPrintServer", your groups are "Printer: HP1", "Printer: Colour_HP2" etc the following (untested) should work:

$sPrintServer="\\MyPrintServer"
$iIndex = 0
$sGroup=EnumGroup($iIndex)
While $sGroup
; Not interested in domain.
If InStr($sGroup,'\') $sGroup=SubStr($sGroup,InStr($sGroup,'\')+1) EndIf
If Instr($sGroup,"Printer: ")=1
$sPrinter=SubStr($sGroup,10)
If AddPrinterConnection($sPrintServer+"\"+$sPrinter)
"ERROR "+@ERROR+": "+@SERROR+@CRLF+"While mapping "+$sPrintServer+"\"+$sPrinter ?
Else
"Printer "+$sPrintServer+"\"+$sPrinter+" mapped ok." ?
EndIf
EndIf
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop

Top
#39103 - 2003-04-16 11:18 AM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
Richard
Thankyou very much, unfortunately my printers are all on different print servers.
The file i had in mind currently had this make up.
Printers.ini or txt
\\server1\printer1
\\server2\printer4
and so on.
if a better setup would make it easier for me im open to suggestions. just thought i could search the file for printer and pull the whole line as my variable. then assign as default.

Thanks again i have a lot to work at now and any progress i'll put back on here.
[Smile]

Top
#39104 - 2003-04-16 11:29 AM Re: Adding Printer Mare
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Don't despair, it only requires a few tweaks.

Have an ini file on your netlogon share in the format:
code:
[PrinterMap]
HP1=\\server1\HP1
ColourHP2=\\otherserver\ColourHP2

Now, change the script slightly so that it reads:

$sPrintServer="\\MyPrintServer"
$sPrinterMap=@LSERVER+"\netlogon\PrinterMap.ini"
$iIndex = 0
$sGroup=EnumGroup($iIndex)
While $sGroup
; Not interested in domain.
If InStr($sGroup,'\') $sGroup=SubStr($sGroup,InStr($sGroup,'\')+1) EndIf
If Instr($sGroup,"Printer: ")=1
$sPrinter=ReadProfileString($sPrinterMap,"PrinterMap",SubStr($sGroup,10))
If $sPrinter
If AddPrinterConnection($sPrintServer+"\"+$sPrinter)
"ERROR "+@ERROR+": "+@SERROR+@CRLF+"While mapping "+$sPrintServer+"\"+$sPrinter ?
Else
"Printer "+$sPrintServer+"\"+$sPrinter+" mapped ok." ?
EndIf
Else
"ERROR: Could not find printer mapping for "+$sPrinter ?
EndIf
EndIf
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop

Top
#39105 - 2003-04-22 10:38 AM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
Thanks again
Giving it a go today.
[Cool]

Top
#39106 - 2003-04-22 01:20 PM Re: Adding Printer Mare
Jac Offline
Fresh Scripter

Registered: 2003-04-11
Posts: 11
Loc: UK
in the line
If InStr($sGroup,'\')
what does the '\' look for
as far as i know its not returned in the group names so im a little confused [Confused]

Top
Page 1 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 483 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.078 seconds in which 0.027 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