Showing results 1 to 9 of 9

Thread: How to login in a multi project surrounding via VBA?

  1. #1
    sebastiank Gast

    Default How to login in a multi project surrounding via VBA?

    Using login functions in multi project surroundings restricts the full functionality of the user administration.

    We recommend not to change the passwords during the runtime (if you would like to do this please contact our support (support@copadata.at).

    In addition you can use a global project where you create you users. This ensures that all projects have the same users saved.

    At first create an online variable where you add the variable username of the system driver (SYSDRV).

    Please add the following code at thisproject in the I-project:
    public WithEvents obOLV As OnlineVariable
    
    Private Sub Project_Active()
        Set obOLV = thisProject.OnlineVariables.CreateOnlineVariables("onlineVar")
        obOLV.Add "Username" 'The Variable Username of the SYSDRV should be added
        obOLV.Define
    End Sub
    
    Private Sub obOLV_VariableChange(ByVal obVar As IVariable)
    Dim vVal As Variant
    Dim i As Integer
    Dim strCurrentUsername As String
        
    vVal = obVar.Value
    If IsError(vVal) Then Exit Sub
    
    strCurrentUsername = Projects.Item("I-project").Passwords.LoggedUsername
    if strCurrentUsername = "SYSTEM" Then
    For i = 0 To Projects.Count - 1
        'In the I project the user is already logged in
        'all projects except the I-project should log in
        If Projects.Item(i) <> "I-Project" Then
            If Projects.Item(i).Passwords.login(strCurrentUsername) = False Then 'if the project log in fails
                MsgBox "System wasn't able to log in the user " & strCurrentUsername & _
                    " in the project " & Projects.Item(i).Name
            End If
        End If
    Next i		
    End if
    End Sub
    
    Private Sub Project_Inactive()
        obOLV.Undefine
        thisProject.OnlineVariables.DeleteOnlineVariables ("onlineVar")
    End Sub

    Now as soon as you log in the user in the I-project, in all sub project the same user will logged in
    Please note that this VBA sample must get altered before you can use it in your project!
    Last edited by sebastiank : 19th September 2007 at 08:12

  2. #2
    sebastiank Gast
    select as best answer

    Default Re: How to login in a multi project surrounding via VBA?

    You can create your users in the I-project and create them dynamically in the sub projects

    Dim struseridi As String
    Dim strusername As String
    Dim struserpw As String
    Dim lLevel As Long
    struseridi = Projects.Item("I-Projekt").Passwords.LoggedUser
    strusername = Projects.Item("I-Projekt").Passwords.LoggedUsername
    lLevel = Projects.Item("I-Projekt").Passwords.ItemUser(struseridi).Level
    struserpw = ""
    Projects.Item("Unterproj").Passwords.CreateUser struseridi, strusername, struserpw, lLevel
    If Projects.Item("Unterproj").Passwords.Login(struseridi) = True Then
        MsgBox "logged in"
    Else
        MsgBox "doesn't work"
    End If

  3. #3
    robertf Gast
    select as best answer

    Idee Re: How to login in a multi project surrounding via VBA?

    It is also possible to use the "UserChange" - Event instead of the Systemdriver variable "Username"

    Dim WithEvents obPWD As Passwords
    
    Private Sub Project_Active()
        'set object for "UserChange" event
        Set obPWD = thisProject.Passwords
    End Sub
    
    Private Sub obPWD_UserChange()
        'this event is called when the logged user has been changed
    End Sub
    
    Private Sub Project_Inactive()
        'release object
        Set obPWD = Nothing
    End Sub

  4. #4
    Join Date
    29.07.2007
    Location
    Germany
    Posts
    195
    select as best answer

    Ausrufezeichen Re: How to login in a multi project surrounding via VBA?

    I had to change the line:

    strCurrentUsername = Projects.Item("I-project").Passwords.LoggedUsername
    to:

    strCurrentUsername = Projects.Item("I-project").Passwords.LoggedUser

    to get the code working!


    Regards,

    H.-P. Babiak

  5. #5
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    882
    select as best answer

    Default Re: How to login in a multi project surrounding via VBA?

    Below you can find a code without using an Onlinecontainer. It uses the above mentioned UserChange() Event. The users are defined in the Global project.

    In addtion all actions are written into the CEL of the I-Project.

    'this code has to be implemented into "thisProject" of the integration project (I-Project)
    
    
    '  hint:
    '     Application.Projects does not work on WebClient-Runtime because the "application" object is in this case the IE and not zenOn
    '     -> always use thisProject.Parent to navigate through a multi-hierarchical project structure
    
    Option Explicit
    
    Dim WithEvents myPwd As Passwords
    
    Private Sub Project_Active()
    
    'set object for "UserChange" event
        Set myPwd = thisProject.Passwords
    End Sub
    
    Private Sub myPwd_UserChange()
    
    Dim iProjCount As Integer
    
        On Error GoTo Errorhandler
    
            'go through all projects
            For iProjCount = 0 To thisProject.Parent.Count - 1
                'log in the user (from the integration project)
                thisProject.Parent.Item(iProjCount).Passwords.Login (myPwd.LoggedUser)
    
                'user could NOT be logged in
                If thisProject.Parent.Item(iProjCount).Passwords.LoggedUser <> myPwd.LoggedUser Then
                    'write to CEL of integration project
                    thisProject.Parent.Item(0).Cel.WriteCelString ("User: """ & myPwd.LoggedUser & """ could not be logged into project: " & thisProject.Parent.Item(iProjCount).Name)
                'user could be logged in
                Else
                    'write to CEL of integration project
                    thisProject.Parent.Item(0).Cel.WriteCelString ("User: """ & myPwd.LoggedUser & """ has been logged into project: " & thisProject.Parent.Item(iProjCount).Name)
                End If
            Next iProjCount
        Exit Sub
    
    Errorhandler:
        'write to CEL of integration project
        thisProject.Parent.Item(0).Cel.WriteCelString ("There was an error while trying to log into the project: " & thisProject.Parent.Item(iProjCount).Name)
    End Sub
    
    Private Sub Project_Inactive()
    
        'release the created object
        Set myPwd = Nothing
    End Sub

    In the attachment you can find a sample project (workspace backup) in zenOn 6.22
    Attached Files Attached Files
    Last edited by herberto : 21st January 2009 at 09:49 Reason: attached file

  6. #6
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    882
    select as best answer

    Idee AW: How to login in a multi project surrounding via VBA?

    Find below a revised version of the VBA code.

    Modifications:
    - no double-login in integration project
    - corrected logout functionality

    Option Explicit
     
    Dim WithEvents myPwd As Passwords
     
    'event fired on starting runtime
    Private Sub Project_Active()
     
        'create object for "UserChange" event
        Set myPwd = thisProject.Passwords
    End Sub
      
    'event fired when a user logged in
    Private Sub myPwd_UserChange()
     
    Dim iProjCount As Integer
    
        On Error GoTo Errorhandler
     
            'go through all projects
            For iProjCount = 0 To thisProject.Parent.Count - 1
                'check if this is the integration project itself (no double login)
                If StrComp(thisProject.Guid, thisProject.Parent.Item(iProjCount).Guid) <> 0 Then
                    'check if the new user is the system user (logout)
                    If myPwd.LoggedUser = "0000" Then
                        thisProject.Parent.Item(iProjCount).Passwords.Logoff
                    Else
                        'log in the user (from the integration project)
                        thisProject.Parent.Item(iProjCount).Passwords.Login (myPwd.LoggedUser)
            
                        'check if the login was successful
                        If thisProject.Parent.Item(iProjCount).Passwords.LoggedUser <> myPwd.LoggedUser Then
                            'user could NOT be logged in
                            'write to CEL of integration project
                            thisProject.Parent.Item(0).Cel.WriteCelString ("User: """ & myPwd.LoggedUser & """ could not be logged into project: " & thisProject.Parent.Item(iProjCount).Name)
                        End If
                    End If
                End If
            Next iProjCount
        Exit Sub
     
    Errorhandler:
       'an error has occured
        If Err.Number <> 0 Then
            'write to CEL of integration project
            thisProject.Parent.Item(0).Cel.WriteCelString ("There was an error while trying to log into the project: " & thisProject.Parent.Item(iProjCount).Name)
            Resume Next
        End If
    End Sub
     
    'event fired on closing runtime
    Private Sub Project_Inactive()
     
        'release the created object
        Set myPwd = Nothing
    End Sub



    Regards,
    Herbert

  7. #7
    Join Date
    25.03.2022
    Posts
    2
    select as best answer

    Default Re: How to login in a multi project surrounding via VBA?

    Hi guys!
    I have the same problem described above but I need a solution in C# or if there is a function already in Zenon that take care of this problem when you need to administrate the same users to several projects...
    Best regards
    Christian

  8. #8
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    882
    select as best answer

    Default Re: How to login in a multi project surrounding via VBA?

    As the above post is pretty outdated - in newer zenon versions there exists a built-in functionality for this. So no need to do this via programming anymore.

    Take a look at this: https://onlinehelp.copadata.com/Cont...F0CF378012E23C


    regards


  9. #9
    Join Date
    25.03.2022
    Posts
    2
    select as best answer

    Default Re: How to login in a multi project surrounding via VBA?

    Thanks Herberto,
    I will look at it...
    Regards
    /Christian

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •