Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Active Directory with Option Explicit 1

Status
Not open for further replies.

Chopstik

Technical User
Oct 24, 2001
2,180
US
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.
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
 
Did you try putting GroupObj up in the list of variables that are Dimmed? or just doing Dim GroupObj somewhere above that point?
 
It would be something so ridiculously simple. What was killing me was that the page itself was not erroring, it simply was not returning any values and I could not think of a reason why.

Sometimes it's just the extra pair of eyes that helps... Thanks! [thumbsup]

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top