Jump to content

IF Statement use with AND OR Operators


jazzyjeff
 Share

Recommended Posts

Hello

I have written a login script and it is working fine. I am running into a situation though where I need to use the AND/OR operators.

Here is an example of what I have:

#include<AD.au3>

If _AD_IsMemberOf("Group1",@username) Then 
DriveMapAdd("E:","")
DriveMapAdd("F:","")
DriveMapAdd("G:","")
ElseIf _AD_IsMemberOf("Group2, @username) And _AD_IsMemberOf("Group1, @username) Then
DriveMapAdd("H:","")
DriveMapAdd("I:","")
DriveMapAdd("J:","")
ElseIf _AD_IsMemberOf("Group3, @username) And _AD_IsMemberOf("Group4, @username) Or  _AD_IsMemberOf("Group2, @username") Or _AD_IsMemberOf("Group5, @username") Then
DriveMapAdd("N:","")
DriveMapAdd("O:","")
DriveMapAdd("P:","")
EndIf

The part I am having problems with is the last part of the "ElseIf" statement. I am basically asking to check if the user logging in is a member of the "Group3" and any of the following:

Group 4

Group 2

Group 5

Then it will map a different set of drives.

The other parts of the If statememnts work, but I just can't get it to work properly when I mix the "AND" and "OR" operators in the same ElseIf statement. How can I get this to work?

Thanks,

Link to comment
Share on other sites

Hi jazzyjeff,

I would say: Just use brackets (like in math):

ElseIf _AD_IsMemberOf("Group3, @username) And ( _AD_IsMemberOf("Group4, @username) Or _AD_IsMemberOf("Group2, @username") Or _AD_IsMemberOf("Group5, @username") ) Then

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

You have another problem too, namely that the first ElseIf doesn't do anything.

ElseIf 2 And 1.

But if 1 was true, then the earlier If would be executed. You need to Change the place of them!

Link to comment
Share on other sites

Thanks A-Jay. I'll give that a try.

MPH, thanks for your reply. When I started creating this login script I was hoping to use SELECT CASE, as I thought it would execute more efficiently. Unfortunately the script kept failing. I ended up setting the script up with If Statements and it works fine. Just had a problem with this bit.

I work for a school and this is a crazy time of year as the teachers appear to have forgotten how to use a computer after their long summer! Once things settle down I'll try and get the SELECT CASE working.

Thanks again.

Link to comment
Share on other sites

How is the 2nd condition ever true? If you are in Group2 and Group1, wouldn't you be meet the first condition (Group1 only) and never see the second condition (Group2 & Group1)? The way that I am thinking it should work is like this.

Select
    Case _AD_IsMemberOf("Group1", @UserName)
        DriveMapAdd("E:", "")
        DriveMapAdd("F:", "")
        DriveMapAdd("G:", "")
        ContinueCase
    Case _AD_IsMemberOf("Group2", @UserName)
        If  _AD_IsMemberOf("Group1", @UserName) Then
            DriveMapAdd("H:", "")
            DriveMapAdd("I:", "")
            DriveMapAdd("J:", "")
        EndIf
        ContinueCase
    Case _AD_IsMemberOf("Group3", @UserName)
        If _AD_IsMemberOf("Group4", @UserName) Or _AD_IsMemberOf("Group2", @UserName) Or _AD_IsMemberOf("Group5", @UserName) Then
            DriveMapAdd("N:", "")
            DriveMapAdd("O:", "")
            DriveMapAdd("P:", "")
        EndIf
EndSelect

Edited by Varian
Link to comment
Share on other sites

BTW: Your quotes '"' are ...hmmm....! Look yourself! Or is this not your original code?

ElseIf _AD_IsMemberOf("Group2, @username) And _AD_IsMemberOf("Group1, @username) Then
                             ^                                      ^

ElseIf _AD_IsMemberOf("Group3, @username) And _AD_IsMemberOf("Group4, @username) Or  _AD_IsMemberOf("Group2, @username") Or _AD_IsMemberOf("Group5, 
                             ^                                      ^                                      ^          ^                           ^
@username") Then
         ^

should'nt this be

ElseIf _AD_IsMemberOf("Group2" @username) And _AD_IsMemberOf("Group1", @username) Then

ElseIf _AD_IsMemberOf("Group3", @username) And _AD_IsMemberOf("Group4", @username) Or  _AD_IsMemberOf("Group2", @username) Or _AD_IsMemberOf("Group5", @username) Then

?

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

Hi AJay,

I am waiting to hear back about the script. That wasn't my original code, just something to give you an idea of what I am trying to achieve. I just made a typo.

Varian,

As I say I haven't had a chance to get the SELECT CASE working as I need yet, but I'll be sure to try this as I think it's the way to go.

Here is my proper code, but I warn you now... It is VERY long for a login script. Works fast though.

Edited by jazzyjeff
Link to comment
Share on other sites

@jazzyjeff

When you press the AutoIt-button just press add and paste the code in afterwards or you get this mess.

Also use the preview button, then you would have seen the mess before posting it.

Link to comment
Share on other sites

Sorry peeps. I have added enough code on here to know how it works. I don't what's wrong with it, but I have tried your suggestions and it won't paste properly. It's starting to **** me off to be honest :-)

I just removed it now anyway, so my "Mess" should no longer clutter this post. I'll try again in a bit and see if it will work in FF.

Link to comment
Share on other sites

Thank you all for your help. Adding the parenthesis as suggested by AJay resolved the issue. I'll start working shortly using the SELECT CASE though.

Also, I tried pasting another script into the forum and it worked fine. Just something in my script is breaking the code function in this site.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...