Solved

ADSI - filtering on the winnt:// provider with javascript

Posted on 2002-07-02
11
2,268 Views
Last Modified: 2008-02-01
This silly little problem is giving me the absolute sh?ts at the moment.  I'm trying to enumerate groups and users on a particular domain, instead my script returns every damn object in the computer collection.  Examine the code below:

  var strDomain = "someDomain/someComputer";
  var Computer = GetObject("WinNT://" + strDomain);
  Computer.Filter = new Array("Group","User");
  // WScript.Echo(Computer.Filter);
  var romulus, remus; //enumeration placeholders
  romulus = new Enumerator(Computer);
  for(;!romulus.atEnd();romulus.moveNext())
    {
    remus = romulus.item();
    WScript.Echo(remus.Name);
    }
  // WScript.Echo("done");

basically this line
  Computer.Filter = new Array("Group","User");
is not doing what the advertisements say, instead of the output being limited to users and groups i'm getting services, devices etc.  I can comment out the line or assign all sorts of rubbish to the variable and makes absolutely no difference to the output.  What am i doing wrong?

Target and Source computer are the same - Winnt 4.0 SP6 with ads.exe (file version 4.71.1015.0) applied.

Regards,

etc.
0
Comment
Question by:klalakomacoi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 9

Expert Comment

by:schmiegu
ID: 7137044
I'm not familiar with JScript, so I will try to translate it to VBScript.

I believe, the problem is in this line:
   Computer.Filter = new Array("Group","User");
I never saw that you could filter by 2 parameters at once

Computer.Filter = Array("user")
for each remus in Computer
  wscript.echo remus.name
next
Computer.filter = Array("group")
for each romulus in Computer
  wscript.echo romulus
next
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7137207
well the MS documentation says you can filter on two parameters at once (i'll find the documentation in question and point you to it), anyway i'll try your suggestion and give it a rip and get back to you.

unfortunately i am not allowed to use VBscript for religious reasons.

regards,

Ian

0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7296649
nope doesn't make a difference if i drop it to only one parameter in the filter statement.

sorry about leaving this question for dead for so long, buried in other crap.

i'll get that MS doco i was talking about earlier and post it.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 9

Expert Comment

by:schmiegu
ID: 7297918
Since it doesn't work with only one filter parameter, there must be another problem.
You're using the 'new' keyword: I'm not familiar with JScript, but in VBScript it's not a valid keyword, while it is in VB. So maybe the line doesn't really filter the results the GetObject.
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7297925
i've pulled out the "new" still no difference, all the objects are output and not a bit of filtering.  does this work the way its supposed to in VBscript?
0
 
LVL 9

Expert Comment

by:schmiegu
ID: 7297945
Yes, it does. For purpose of verification I'm running this script at the moment:

Option Explicit
dim myDomains, myDom
dim myUsers, myComp
dim oFSO, oFile
set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.CreateTextFile("DomainUsers.csv", True)
  oFile.WriteLine("Name" & vbTab & "Full Name")
  set myUsers = GetObject("WinNT://MyDomain")
  myUsers.Filter = Array("User")
  for each myUser in myUsers
    oFile.WriteLine(myUser.Name & vbTab & myUser.FullName)
  next
oFile.Close
MsgBox "Done"

I only got user accounts. Changing the filter to "computer" only showed computers. (I only got an error, because I didn't delete the .FullName property from the script - this isn't supported by computers)
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7298062
you're right, it works like a charm.  I'm sorry but have to leave you now, i have to do a ritual cleansing ceremony because i used VBscript.

Its obviously an issue between JavaScript and ADSI - JavaScript can't pass parameters to the Filter attribute properly.

you know any JavaScript nutcases who can shed light on this?
0
 
LVL 9

Accepted Solution

by:
schmiegu earned 200 total points
ID: 7298119
Besides the infos from msdn.microsoft.com IMO the best site for scripting is:
http://cwashington.netreach.net

Other links I've bookmarked, but don't find so helpful:
http://home.att.net/~wshvbs/
http://desktopengineer.com/
0
 
LVL 3

Author Comment

by:klalakomacoi
ID: 7332332
well i guess thats the best we're going to get on this so i'll close the question and give schmeigu the points.  If i ever get any answer on how to do this in js i'll forward it on.

Schmiegu, post a comment at Q_20319811 and Q_20319810 to clean up the 40 available that side.

Regards and thanks for your help
0
 

Expert Comment

by:KarelK
ID: 12295464
Array("User") in WBScript != new Array("User") in JavaScript. In JavaScript is Array an object.
0
 

Expert Comment

by:EnterpriseAutomater
ID: 23940696
but you can convert a javascript array to a vbscript SAFEARRAY if you cheat and use the scripting.dictionary object..

I've tested this process with filtering for computers and users through GetObject("WinNT://<domain>") and it works exactly as expected -- though there are a few more hoops..


function JS2VBArray( objJSArray )
{
    var dictionary = new ActiveXObject( "Scripting.Dictionary" );
    for ( var i = 0; i < objJSArray.length; i++ )
    {
        dictionary.add( i, objJSArray[ i ] );
    }
 
    return dictionary.Items();
}
var myDomains, myDom;
var myUsers, myComp,myResults;
 
// Substitue <domain> with the netbios name of your domain;
myResults = GetObject("WinNT://<domain>");
 
myResults.Filter = JS2VBArray(new Array("Computer"));
 
//This line below creates a filter on two classes
//myResults.Filter = JS2VBArray(new Array("Computer,User"));
 
var e = new Enumerator(myResults);
for (; !e.atEnd();e.moveNext())
{
	myUser = e.item();
	WScript.StdOut.WriteLine(myUser.Name + ":\t" + myUser.Class);
	//oFile.WriteLine(myUser.Name + "," + myUser.FullName)
}

Open in new window

0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Choosing a core focus or particular set of features and options can be tough. To help out, we’re going to highlight a handful of things your business needs on one of your social media pages. In other words, if one of these is missing, you should imp…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question