Page 1 of 1 1
Topic Options
#116068 - 2004-03-12 04:16 PM Output without error 0
otf Offline
Getting the hang of it

Registered: 2003-11-21
Posts: 53
Loc: Scotland
hello,
I'm running this script:
$domain = GetObject("WinNT://blahblah.blahblah.blah.blah)
$domain.filter = "user"
For Each $user in $domain
? $user.name
RedirectOutput("domainusers.log")
Next

this works great, output's to a log file BUT
it adds a '0' at the end of every username, signifying process success i think.
How can i get it to output but missing out the '0' code at the end of username?

cheers,
otf

Top
#116069 - 2004-03-12 04:23 PM Re: Output without error 0
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$nul=RedirectOutput("domainusers.log")
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#116070 - 2004-03-12 04:28 PM Re: Output without error 0
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Try this instead...

Code:

$domain = GetObject("WinNT://"+@Domain)
$nul=RedirectOutput("domainusers.log")
For Each $object in $domain
If $object.class = "user"
? $object.name
Endif
Next



You were getting a 0 because you were not trapping the return code from the RedirectOutput function. Notice I added a $nul= to the front of it so that the return code of 0 is now sent to the $nul variable and not to the console. I also moved the RedirectOutput outside of the For Next loop since you only have to specify it once. You code was also returning groups as well as users so I added the .class If Endif portion to be sure it only logs users.

Top
#116071 - 2004-03-12 04:43 PM Re: Output without error 0
otf Offline
Getting the hang of it

Registered: 2003-11-21
Posts: 53
Loc: Scotland
many thanks,
man you guys are quick
i'm new to KiX but i'm learning fast
i'll give it a try
cheers!

Top
#116072 - 2004-03-12 04:44 PM Re: Output without error 0
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Even better:
Code:
If RedirectOutput("domainusers.log",1)
"Whoops! Cannot open the output log!" ?
"Error "+@ERROR+": "+@SERROR ?
EndIf

$domain = GetObject("WinNT://"+@Domain)
For Each $object in $domain
If $object.class = "user"
? $object.name
EndIf
Next



Error return values are usually (although not always) worth checking. If you don't, they'll bite you in the bum later.

Top
#116073 - 2004-03-12 04:46 PM Re: Output without error 0
otf Offline
Getting the hang of it

Registered: 2003-11-21
Posts: 53
Loc: Scotland
works great, cheers lads!
Top
#116074 - 2004-03-12 06:53 PM Re: Output without error 0
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also the FAQ Forum under Why does the console display zeros and ones (amongst others)?
_________________________
There are two types of vessels, submarines and targets.

Top
#116075 - 2004-03-12 08:56 PM Re: Output without error 0
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Quote:

You code was also returning groups as well as users so I added the .class If Endif portion to be sure it only logs users.




he was on the right track with the

$domain.filter = "user"

but the .filter object needs an array passed to it for it to work.

$domain.filter = "user",""

or

$domain.filter = split("user")

will give .filter the needed array value for it to work.


Edited by Bryce (2004-03-12 09:00 PM)

Top
#116076 - 2004-03-12 08:59 PM Re: Output without error 0
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Thanks Bryce...I wasnt sure how to make the .Filter work so I just did the If Endif on the .Class property.
Top
#116077 - 2004-03-12 09:29 PM Re: Output without error 0
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Plus, using a filter will speed up enumerations, especially in large domains.
Top
#116078 - 2004-03-12 10:52 PM Re: Output without error 0
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
You are correct Chris...Did some timings and the look up using the .Filter was over twice as fast.
Top
#116079 - 2004-03-13 03:16 AM Re: Output without error 0
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Which is not surprising as the filter is applied on the server-side and the script thus receives less data nad doesn't need to filter it.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.063 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org