Solved

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

Posted on 2002-07-02
11
2,206 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
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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
auto copy 8 614
Need the Best Data Leakage Protection (Cloud Based) 1 356
How to change folder redirection to a new server 5 733
Update a root certificate 8 652
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…
Note: This is the second blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   Every month t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now