ADSI call works in vbscript fails in jscript 
Author Message
 ADSI call works in vbscript fails in jscript

I'm trying to check for group memberships in a login script on W2k
I had real problems using LDAP:// and switched to WinNT:// but this fails
in jscript (which I prefer syntax wise over VBScript), I've stripped it
down to the bones that demonstrates the problem.

Any ideas why the adsobjs.groups property works in vbs but not js ?

======= works.vbs
dim networkobj
dim struser
dim strdomain
dim adsobj
dim groupcoll  
dim groupobj

set objnetwork = WScript.CreateObject("WScript.Network")
struser = objnetwork.UserName
strdomain = objnetwork.UserDomain
MsgBox strDomain & "\" & strUser

set adsobj = GetObject("WinNT://" & strdomain & "/" & struser)
set groupcoll = adsobj.groups

For each groupobj in groupcoll
   MsgBox groupobj.name
Next

======= fails.js
var networkobj;
var struser;
var strdomain;
var adsobj;
var groupcoll;
var groupobj;
var shellobj;

shellobj = WScript.CreateObject("WScript.Shell");
networkobj = WScript.CreateObject("WScript.Network");
struser = networkobj.UserName;
strdomain = networkobj.UserDomain;

shellobj.Popup(strdomain + "\\" + struser);

adsobj = GetObject("WinNT://" + strdomain + "/" + struser);
groupcoll = adsobj.groups;
   // "error 800A01B6 object doesn't support this property or method"

for(groupobj in groupcoll)
  {    
  WScript.Popup(groupobj.name);
  }

--
Andy Burns



Sat, 26 Apr 2003 03:00:00 GMT  
 ADSI call works in vbscript fails in jscript

Quote:

>Any ideas why the adsobjs.groups property works in vbs but not js ?
>groupcoll = adsobj.groups;
>   // "error 800A01B6 object doesn't support this property or method"

forgot to add that if I change this to groupcoll = adsobj.groups() then it
doesn't fail, but it doesn't return any of the actual groups either :-(

--
Andy Burns



Sat, 26 Apr 2003 03:00:00 GMT  
 ADSI call works in vbscript fails in jscript
...
groupcoll = adsobj.groups();
enumGroups = new Enumerator(groupcoll)

// or drop the groupcoll variable
// and just use adsobj.groups() directly...
// enumGroups = new Enumerator(adsobj.groups())

for(; !enumGroups.atEnd();enumGroups.moveNext() )
  {
  groupobj = enumGroups.item();
  WScript.Popup(groupobj.name);
  }
...

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> I'm trying to check for group memberships in a login script on W2k
> I had real problems using LDAP:// and switched to WinNT:// but this fails
> in jscript (which I prefer syntax wise over vbscript), I've stripped it
> down to the bones that demonstrates the problem.

> Any ideas why the adsobjs.groups property works in vbs but not js ?

> ======= works.vbs
> dim networkobj
> dim struser
> dim strdomain
> dim adsobj
> dim groupcoll
> dim groupobj

> set objnetwork = WScript.CreateObject("WScript.Network")
> struser = objnetwork.UserName
> strdomain = objnetwork.UserDomain
> MsgBox strDomain & "\" & strUser

> set adsobj = GetObject("WinNT://" & strdomain & "/" & struser)
> set groupcoll = adsobj.groups

> For each groupobj in groupcoll
>    MsgBox groupobj.name
> Next

> ======= fails.js
> var networkobj;
> var struser;
> var strdomain;
> var adsobj;
> var groupcoll;
> var groupobj;
> var shellobj;

> shellobj = WScript.CreateObject("WScript.Shell");
> networkobj = WScript.CreateObject("WScript.Network");
> struser = networkobj.UserName;
> strdomain = networkobj.UserDomain;

> shellobj.Popup(strdomain + "\\" + struser);

> adsobj = GetObject("WinNT://" + strdomain + "/" + struser);
> groupcoll = adsobj.groups;
>    // "error 800A01B6 object doesn't support this property or method"

> for(groupobj in groupcoll)
>   {
>   WScript.Popup(groupobj.name);
>   }

> --
> Andy Burns



Sat, 26 Apr 2003 03:00:00 GMT  
 ADSI call works in vbscript fails in jscript

Quote:

>groupcoll = adsobj.groups();
>enumGroups = new Enumerator(groupcoll)

>for(; !enumGroups.atEnd();enumGroups.moveNext() )
>  {
>  groupobj = enumGroups.item();

   ^
"object doesn't support this method or property error" now occurs here
instead

Quote:
>  WScript.Popup(groupobj.name);
>  }

Thanks for the reply, I've just been trying with enumerators using the
code from the fso.Drives example in js55.chm and got nowhere :-(

Even your suggested code doesn't run for me as indicated above

I've been looking at the ADSI interfaces, presuming that the
GetObject(WinNT:// ...) returns something which implements IADsUser, the
Groups() Method returns IADsMembers* which doesn't have a .Name property
so how does even the vbscript work ?
--
Andy Burns



Sat, 26 Apr 2003 03:00:00 GMT  
 ADSI call works in vbscript fails in jscript

Quote:

>enumGroups = new Enumerator(groupcoll)

I was wondering why I'd ever used

for(obj in coll)
  {
  ...
  }

I could swear that one version of the help file I have showed it as valid
for collections rather than arrays and objects in jscript, but I can't
find it now, maybe I was looking at a vbscript help file by mistake.

--
Andy Burns



Sat, 26 Apr 2003 03:00:00 GMT  
 ADSI call works in vbscript fails in jscript

Quote:

>>  groupobj = enumGroups.item();

>   ^
>"object doesn't support this method or property error" now occurs here
>instead

>>  WScript.Popup(groupobj.name);

    ^
Turns out it was actually here that the error was occurring
replaced WScript.Popup() with my myshellobj.Popup() and its all fine,
thanks very much for pointing me in the right direction - the only think
now is that enumeration the groups seems *very* slow :-(

the working jscript snippet is posted below in case it benefits anyone
else ...

objShell = WScript.CreateObject("WScript.Shell");
objNetwork = WScript.CreateObject("WScript.Network");
strUser = objNetwork.UserName;
strDomain = objNetwork.UserDomain;

objShell.Popup(strDomain + "\\" + strUser);

objAds = GetObject("WinNT://" + strDomain + "/" + strUser);
enumGroups = new Enumerator(objAds.Groups())

for(; !enumGroups.atEnd(); enumGroups.moveNext() )
  {
  objGroup = enumGroups.item();
  objShell.Popup(objGroup.Name);
  }

--
Andy Burns



Sun, 27 Apr 2003 03:00:00 GMT  
 ADSI call works in vbscript fails in jscript

Hi,

Quote:
> I was wondering why I'd ever used

> for(obj in coll)
>   {
>   ...
>   }

> I could swear that one version of the help file I have showed it as valid
> for collections rather than arrays and objects in jscript, but I can't
> find it now, maybe I was looking at a vbscript help file by mistake.

You are correct, it works for enumerating properties but not
collections. It's confusing basically, but you have to get used to it.
See the "for...in" statement in the docs for the scant explanation.

You can sometimes do tricks to make things work with for...in instead of
the enumerator object.

--
Gerry Hickman (London UK)



Sun, 27 Apr 2003 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. ADSI call works in vbscript fails in jscript

2. ADSI call works in vbscript fails in jscript

3. ASP ADSI works when browsing locally but fails remotely

4. Calling Java from Javascript: Works in NN, fails in IE

5. Anyone know why JScript does not work with ADSI and multivalued attributes

6. Reg Exp works in JScript not VBScript

7. VBScript-to-Jscript Conversion: One Works, the Other Not

8. Works in JScript but no VBScript

9. Works in JScript but no in VBScript

10. Include works Jscript but not with Vbscript

11. calling vbscript function from jscript?

12. Call VBScript Form JScript

 

 
Powered by phpBB® Forum Software