Jump to content

Continuecase Problem


Recommended Posts

I am not sure, but is this a feature or a bug?

When using ContinueCase in the following script:

Select
    Case 1
        MsgBox(0,"","This is the case 1")
        ContinueCase
    Case 0
        MsgBox(0,"","This box should never show up")
EndSelect

The second message box always shows up. Shouldn't ContinueCase also check the condition of the second case?

Or have I done something wrong??

p.s I am using the latest beta

Edited by teristam
Link to comment
Share on other sites

this is what the help files says:

"Abort the current case and continue a case into the next case in a Select or Switch block."

"Normally in a Select or Switch block, a case ends when the next Case statement is encountered. Executing the ContinueCase will tell AutoIt to stop executing the current case and start executing the next case. "

Link to comment
Share on other sites

  • 1 year later...

Thanks!

But I think the condition should first be checked before executing the code, otherwise what's the use of ContinueCase?.....

Yes i'm also curious how Continuecase works, i'm trying to build a login script based on Case Select.

My first thought was it indeed checked the next Case value before running it, apparantly not.

What other way can i use to make this login script work, the idea is that a user is a member of different security groups.

Therefore multiple cases are true and some are not, based on a "continue to check case values when specified" multiple networkconnections are added in the end.

Please advise! <_<

Func UserInGroup($Domain, $UserName, $InGroup);Define a Functionname to Check if User is in a group 
    Local $objUser = ObjGet("WinNT://" & $Domain & "/" & $UserName)
    For $oGroup in $objUser.Groups
        If $oGroup.Name = $InGroup Then Return 1
    Next
    Return 0
EndFunc 

Func ComError();Define a Functionname for COM Error function
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc

$oMyError = ObjEvent("AutoIt.Error", "ComError")
Select
    Case UserInGroup(@LogonDomain,@UserName,"Group1")
        DriveMapAdd("E:","\\server01\share1")
        MsgBox(0,"","Member Group1")
        ContinueCase
    Case UserInGroup(@LogonDomain,@UserName,"Group2")
        DriveMapAdd("F:", "\\server01\share2"
        MsgBox(0,"","Member Group2")
        ContinueCase
    Case UserInGroup(@LogonDomain,@UserName,"Group1Extra")
        DriveMapAdd("G:", "\\server02\extra"
        MsgBox(0,"","Member Group1Extra")
        ContinueCase
    Case UserInGroup(@LogonDomain,@UserName,"Special")
        DriveMapAdd("H:","\\server2\special")
        MsgBox(0,"","Member Special")
EndSelect
Link to comment
Share on other sites

If UserInGroup(@LogonDomain,@UserName,"Group1") Then
        DriveMapAdd("E:","\\server01\share1")
        MsgBox(0,"","Member Group1")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group2") Then
        DriveMapAdd("F:", "\\server01\share2"
        MsgBox(0,"","Member Group2")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group1Extra") Then
        DriveMapAdd("G:", "\\server02\extra"
        MsgBox(0,"","Member Group1Extra")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Special") Then
        DriveMapAdd("H:","\\server2\special")
        MsgBox(0,"","Member Special")
EndIf

Edited by weaponx
Link to comment
Share on other sites

If UserInGroup(@LogonDomain,@UserName,"Group1") Then

DriveMapAdd("E:","\\server01\share1")

MsgBox(0,"","Member Group1")

EndIf

Hi weaponx,

I already thought of that version, but it has a weakness for using it in my "case", that's why i hoped Continuecase was the answer.

Let me explain what it is i'm looking for: Some users are members of a security group (example group1) so that they can access Intranet and are also members of External.

But by giving them these rights they also execute the mappings of Group1 during loginscript.

If UserInGroup(@LogonDomain,@UserName,"External") Then
DriveMapAdd("E:","\\server01\share1")
MsgBox(0,"","Member Group1")
Exit
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group1") Then
DriveMapAdd("E:","\\server01\share1")
MsgBox(0,"","Member Group1")
EndIf

By using an exit code it would stop the script entirely, in stead of skipping the rest of the cases.

My thought => by NOT using an continuecase it would proceed with the rest of the script below EndSelect.

It's hard to explain, do you understand it?

Edited by Ruigerock
Link to comment
Share on other sites

Easy.

mapDrives()
Func mapDrives()
If UserInGroup(@LogonDomain,@UserName,"Group1") Then
        DriveMapAdd("E:","\\server01\share1")
        MsgBox(0,"","Member Group1")
Return ;<----Leave function
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group2") Then
        DriveMapAdd("F:", "\\server01\share2"
        MsgBox(0,"","Member Group2")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group1Extra") Then
        DriveMapAdd("G:", "\\server02\extra"
        MsgBox(0,"","Member Group1Extra")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Special") Then
        DriveMapAdd("H:","\\server2\special")
        MsgBox(0,"","Member Special")
EndIf
EndFunc

You just have to nest your if's properly, using ElseIf and Else

Edited by weaponx
Link to comment
Share on other sites

mapDrives()
Func mapDrives()
If UserInGroup(@LogonDomain,@UserName,"Group1") Then
        DriveMapAdd("E:","\\server01\share1")
        MsgBox(0,"","Member Group1")
Return ;<----Leave function
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group2") Then
        DriveMapAdd("F:", "\\server01\share2"
        MsgBox(0,"","Member Group2")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Group1Extra") Then
        DriveMapAdd("G:", "\\server02\extra"
        MsgBox(0,"","Member Group1Extra")
EndIf
If UserInGroup(@LogonDomain,@UserName,"Special") Then
        DriveMapAdd("H:","\\server2\special")
        MsgBox(0,"","Member Special")
EndIf
EndFunc
Thanks weaponx for illustrating Func;return;endfunc

I didn't know such a combo existed <_<

The second combo If..Then..Else..EndIf with other "If..Then..EndIf " inside of it was also new to me.

Greetings and a nice weekend.

Link to comment
Share on other sites

Select/Switch just don't seem like the proper tools. This seems more straight forward than all that (but may just be personal preference/prejudice):

$objUser = ObjGet("WinNT://" & @LogonDomain & "/" & @UserName)
$sGroupList = ";"
For $oGroup in $objUser.Groups
    $sGroupList &= $oGroup.Name & ";"
Next

$sMsg = "Mapped drives for the following group memberships:" & @CRLF
If StringInStr($sGroupList, ";" & "Group1" & ";") Then
    DriveMapAdd("E:","\\server01\share1")
    $sMsg &= "Group1 (E:)" & @CRLF
Else
    If StringInStr($sGroupList, ";" & "Group2" & ";") Then 
        DriveMapAdd("F:", "\\server01\share2"
        $sMsg &= "Group2 (F:)" & @CRLF
    EndIf
    If StringInStr($sGroupList, ";" & "Group1Extra" & ";") Then 
        DriveMapAdd("G:", "\\server02\extra"
        $sMsg &= "Group1Extra (G:)" & @CRLF
    EndIf
    If StringInStr($sGroupList, ";" & "Special" & ";") Then 
        DriveMapAdd("H:","\\server2\special")
        $sMsg &= "Special (H:)" & @CRLF
    EndIf
EndIf
MsgBox(64, "Drive Maps", $sMsg)

It's at least faster and doesn't annoy with many pop-ups.

<_<

Edit: Tweak to add ";" to substring to prevent partial matches.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...