Ok, I've come across something that I don't quite ken. I'm hoping someone can explain to me why this should be the case. I have stolen borrowed a script from markdmac and used it to query against a global group in Active Directory. However, if I use the Option Explicit command at the top of the page, there is no information in the GroupObj object. If I leave the Option Explicit out, it works as expected. Can someone please explain why this should be the case (or if I'm doing something wrong)? (Also, bear in mind that I am just learning how this process works so all advice if there is a better way to do it is greatly appreciated.) Thanks.
------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
Code:
<%@ Language="VBScript" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<link rel="stylesheet" type="text/css" href="link4style1.css">
<title>Please enter your suggestion</title>
</HEAD>
<%
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path, strMember
Set WSHShell = server.CreateObject("WScript.Shell")
Set WSHNetwork = server.CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") 'Is this necessary? HLC 5/9/06
'Grab the user name
UserString = WSHNetwork.UserName
Response.Write UserString & " is the current user.<br>"
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Now check for group memberships
[COLOR=red]'This is the section where I can not see any values if I have the Option Explicit set at the top of the page.[/color]
For Each GroupObj In UserObj.Groups
'Test for "RL.Corporate.RealEstate.Users" group. If member, then complete page. If not, then error message.
if GroupObj.Name = "RL.Corporate.RealEstate.Users" then
strMember = "CRE"
exit for
else
strMember = "Non-CRE"
end if
Next
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHShell = Nothing
Set WSHPrinters = Nothing
'Quit the Script
wscript.quit
'If not a CRE member, this will present an error message and redirect them to the Real Estate home page.
if strMember = "Non-CRE" then
Response.Write "<h5>This page is for Corporate Real Estate personnel only. <br>" & _
"Please click <a href='[URL unfurl="true"]http://www.AnotherIntranetSite.com'>here</a>[/URL] to " & _
"return to the Corporate Real Estate home page.<h5>"
Response.Flush
Response.End
end if
------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill