We help IT Professionals succeed at work.

VBscript code conversion...Checking NT Groups.

ouaouaron
ouaouaron asked
on
Medium Priority
246 Views
Last Modified: 2008-02-01
Can anyone turn this code in javascript please...

Sub Session_OnStart
   
   
    strUsername=Replace(ucase(Request.ServerVariables("LOGON_USER")) , "\", "/")  
    set adsUser = getobject("WinNT://" & strUsername)
    for each group in adsUser.groups
         GrpList = GrpList & lcase(trim(group.name)) & ";"
    next

    if instr(1, GrpList ,"SecureNTGroupName") then session("permission") = "OK"
End sub

Thanks..!
Comment
Watch Question

Commented:
There isn't Javascript eqquivalent. This is a secure language that doesn't allow so much access to private environments.

Perhaps I'm wrong, but standard javascript doesn't allow this kind of visibility.

Author

Commented:
Hi rabanero, thanks for your time...

Hi already use this server side javascript in an asp page :

...
var MembreNT
var ...
...
MembreNT = GetObject('WinNT://SAAQ/DI_COURRIEL_SANS_LIM');
if (MembreNT.IsMember('WinNT:' + fNormalise_Code_Usager(sUsager)))
   eEstMembre = 1;
else
   eEstMembre = 0;
...

I retrived the NT group and use IsMember to find if my user is in this group.

But now, some security patches have been put on my server and this does not work anymore. I can't create a group object. I've found that with vbscript i can have the same result by creating a user object and then check is group :

    set adsUser = getobject("WinNT://" & strUsername)
    for each group in adsUser.groups
         GrpList = GrpList & lcase(trim(group.name)) & ";"
    next
// then check if my group is in GrpList.
 
This work well in vbscipt but i have to do it in javascript... Like i did when i was creating a group object. I just don't know how to do a FOR EACH in javascript..! :) (nor an instr...)

Thanks !
Commented:
For Each translates to:

for (i=0; i<adsUser.groups.length; i++)
{
    GrpList += adsUser.groups[i].name + ";";
}

If instr(1, GrpList ,"SecureNTGroupName") Then translates to:

if (GrpList.indexOf("SecureNTGroupName") > -1)
{

}

Explore More ContentExplore courses, solutions, and other research materials related to this topic.