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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch (again) 1

Status
Not open for further replies.
Aug 20, 2001
23
GB
Hi

I have inherited a vbscript in my establishment that checks whether a user is in a security group and creates their user area and applies a range of permissions.

I've recently had to move 600 users to a new server and want to alter the script to include appropriate references to this new server.

I've looked through the FAQs here and trawled the web for some information but am drawing a blank - probably due to a poor understanding of the subject area.

Code:
' AD's MMC passes arguments to WScript
Set wshArguments = WScript.Arguments

Dim objUser, objGroupDict, objFSO, objShell

' The User Object and its Properties are passed as the first argument
Set objUser  = GetObject(wshArguments(0))
Set objFSO   = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

Dim strOutput

CreateMemberOfObject

If CBool(ObjGroupDict.Exists("CN=Students" AND "CN<>Year 7 Students" OR "CN<>Year 8 Students")) = True Then

However, this last line reports a type mismatch and yes this is the line I altered. I altered it from
Code:
  If CBool(ObjGroupDict.Exists("CN=Students")) = True Then
which worked fine but not for my relocated users.

I want the next set of statements to apply to students not in either of these years. I could include another 6 Elseif statements but thought there may be a more elegant solution here.

I am not a scripter and so am learning as I go here so any help would be much appreciated.

Not sure here whether CN is referencing the OU or the Security Group (although objGroupDict would suggest Group membership as opposed to OU membership).

Any assistance greatly appreciated.

Bob

Fast, Cheap and Good pick two because if it's fast and cheap it won't be good, if it's cheap and good it won't be fast and if it's fast and good it won't be cheap
 
Hi

I've managed to fix this by changing the select statement to

Code:
If (CBool(ObjGroupDict.Exists("CN=Year 9 Students")) OR (ObjGroupDict.Exists("CN=Year 10 Students")) OR (ObjGroupDict.Exists("CN=Year 11 Students")) OR (ObjGroupDict.Exists("CN=Year 12 Students")) OR (ObjGroupDict.Exists("CN=Year 13 Students"))) = True Then

Tried to change this by using

Code:
If (CBool(ObjGroupDict.Exists("CN=Year 9 Students")) AND (ObjGroupDict.Exists("CN<>Year 7 Students")) OR (ObjGroupDict.Exists("CN<>Year 8 Students")))= True Then

Can't get that to work though and I suspect it's my bracket placement.

Thanks for looking though and I'll continue to explore making it more elegant (if I can).

The post by keybdcowboy (thread329_107842) really helped as well and I've starred him for it.

Thanks

Bob

Fast, Cheap and Good pick two because if it's fast and cheap it won't be good, if it's cheap and good it won't be fast and if it's fast and good it won't be cheap
 
If you want year 9 students who aren't also year 7 or 8 students, the "or" part should be in their own set of parenthesis:

Code:
If (CBool(ObjGroupDict.Exists("CN=Year 9 Students")) AND [highlight]([/highlight](ObjGroupDict.Exists("CN<>Year 7 Students")) OR (ObjGroupDict.Exists("CN<>Year 8 Students"))[highlight])[/highlight])= True Then
 
Hi guitarzan

Thnaks for getting back to me. I tried your varaiation as below

Code:
If (CBool(ObjGroupDict.Exists("CN=Students")) AND ((ObjGroupDict.Exists("CN<>Year 7 Students")) OR (ObjGroupDict.Exists("CN<>Year 8 Students"))))= True Then

The student is a member of the students group (as all students are). However, it doesn't evaluate the condition and moves straight to the end of the script reporting student must be a member of students group. It would appear it's not evaluating this condition.

I'll keep digging

Thanks

Bob

Fast, Cheap and Good pick two because if it's fast and cheap it won't be good, if it's cheap and good it won't be fast and if it's fast and good it won't be cheap
 
Make sure ObjGroupDict contains what you expect. If it does, the logic will be easy. If it does not, you will have to post more code:
Code:
wscript.echo "CN=Students is " & (CBool(ObjGroupDict.Exists("CN=Students")) 
wscript.echo "CN<>Year 7 Students is " & (CBool(ObjGroupDict.Exists("CN<>Year 7 Students")) 
wscript.echo "CN<>Year 8 Students is " & (CBool(ObjGroupDict.Exists("CN<>Year 8 Students"))
 
What about this ?
Code:
If ObjGroupDict.Exists("CN=Students") And Not ObjGroupDict.Exists("CN=Year 7 Students") And Not ObjGroupDict.Exists("CN=Year 8 Students") Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

guitarzan thanks for that I'll look into producing that output to check things out.

PHV that worked a charm - thanks very much for the suggestion.

As I pointed out I'm a novice scripter I tend to use batch files constructed through spreadsheets mainly which although effective are fairly rbar in their approach.

Thanks again for the answers and I'll keep researching to make sure I understand the problem and the solution offered.

Regards

Bob

Fast, Cheap and Good pick two because if it's fast and cheap it won't be good, if it's cheap and good it won't be fast and if it's fast and good it won't be cheap
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top