Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Track the computer where the user last logged on

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Track the computer where the user last logged on

    During my logon script I would like to track the computer name where the user is logging on. I would like to write it to a field located in my emp (short for employee) table for the user logging on.

    Table: emp
    Field: emplastpc

    gvuser = their unique username

    Below is a section of the logon script where I would like to place the code.

    I believe I would use something like
    emp.emplastpc = api_getmachinename()

    although I am unsure how to place the value in the field for the user currenlty logging in? Any help would be greatly appreciated.

    if alltrim(lower(vuserpass)) = alltrim(lower(vpassfound)) ' Password matches too
    gvuser = alltrim(lower(gvuser))

    'Resets the employees password by clearing the vuserpass variable
    vuserpass = ""

    'Open Employee Table (lookupc's will not be required to open and close the table)
    DIM tbl as P
    tbl=table.open("emp",FILE_RO_SHARED)

    'Set Global Variable gvEmpName equal to the Employees full name
    gvEmpName = lookupc("F", gvuser, "alltrim(Empfname)+' '+ alltrim(Emplname)", "emp","_Emplognid")

    'Set Global Variable gvEmpid equal to the Employees ID Number
    gvEmpid = lookupc("F", gvuser, "alltrim(Empid)", "emp","_Emplognid")

    emp.emplastpc = api_getmachinename()

    'Close Employee table
    tbl.close()

    #2
    Re: Track the computer where the user last logged on

    Once the table is open, you'll need to find the record you want to change. Let's assume you're already on that record...

    tbl.change_begin()
    tbl.emplastpc = api_getmachinename()
    tbl.change_end(.T.)

    Getting to the emp record you need...

    query.filter = "_Emplognid = " + _Emplognid
    or
    query.filter = "_Emplognid = '" + _Emplognid + "'"
    depending on whether it's numeric or char.


    qry = tbl.query_create()
    nrecs = qry.records_get()

    If you found a record then your employee is there, if not, then you'd have to do a tbl.enter_begin() to start a new record.

    Comment


      #3
      Re: Track the computer where the user last logged on

      When opening the table the code is:

      DIM tbl as P
      tbl=table.open("emp",FILE_RW_SHARED)

      The table must be in read/write mode either shared or exclusive mode (shared will be fine I think).

      Comment


        #4
        Re: Track the computer where the user last logged on

        David and Garry, Thank you for your responses.

        I borrowed from both of your posts and the results are shown at the bottom of this post. Since my last post I added another field "Emplastoff" where I also capture the date and time the employee logs off.

        Being new to Alpha I have some basic questions on how queries work. I apologize up front if I do not use proper terminology, please feel free to correct me.

        1. Once a query is created, do all subsequent queries use it unless another query is specified?

        2. Will a query automatically "reset" when a table is closed?

        3. In this case the query only returns one record so a record "order" is irrelevant although if I were returning multiple results what would the "order" code be if I wanted to order the code based on the employee last name field (Emplname)?
        Would it be query.order = "Emplname"

        Example of working code I have now.
        DIM tbl as P
        tbl=table.open("emp",FILE_RW_SHARED)

        'Filter the EMP table to the user currently logging on.
        DIM qry as P
        query.filter = "Emplognid = '" + gvuser + "'"
        qry = tbl.query_create()

        'Set EMP - Emplastpc to the computername of the user currently logging on.
        tbl.change_begin()
        tbl.emplastpc = api_getmachinename()
        tbl.emplastoff = now()
        tbl.change_end(.T.)

        'Close Employee table
        tbl.close()

        Comment


          #5
          Re: Track the computer where the user last logged on

          As you have a field Emplognid which I assume is the table primary key and is unique and has an index named "idx" (not a name I would use but just to make it obvious in code below),

          tbl = table.open("emp",FILE_RW_SHARED)
          tbl.index_primary_put("idx")
          recnum = tbl.fetch_find(vUsername)
          IF recnum > 0 THEN ' a record exists
          tbl.change_begin()
          tbl.emplastpc = api_getmachinename()
          tbl.emplastoff = now()
          tbl.change_end(.T.)
          END IF
          tbl.close()

          Also easy in above code if no record exists (recnum < 1) then easy to add new record. I have highlighted the new methods you may wish to study up on.

          I create a query every time I need it rather than assume it exists.
          Your understanding of order is correct. If not specified it is the natural order of the table which is recno()

          Comment


            #6
            Re: Track the computer where the user last logged on

            I am following this thread with interest and want to show what I did.

            I start the task with the autoexec script. From there I got the user/computer name and the start time. When the database will be closed the script log out the user.

            These information are write to who_is and who_is_log database. who_is database will show who is online at the moment. Therefore I use the script "who_is_online". The log database is for a report, so you can see which user at what time used the database.

            Cornelius

            Comment


              #7
              Re: Track the computer where the user last logged on

              Garry and Corelius, thank you. I have a question(s) for both of you. :)

              In my case, I run the "tracking" code discussed in this post where I have already verified a user exists in the table so there is no need to create an additional record as you suggested.

              1. Regarding the use of an index. The Emplognid is unique in the Emp table and I have an index established for it called _Emplognid. The Order Expression for _Emplognid is ascending on the Emplognid field.

              If I add the following line of code: tbl.index_primary_put("_Emplognid")

              Will it use the _Emplognid for the query?

              Corelius - I do currently do not log the employees authentication as you are doing it although have thougth about something similiar a couple of times, good idea. I am curious do you timestamp when the user logs off also? How do you track when they go offline/logout? What happens if they jsut close the app, how does it track their logout?
              Last edited by Scott Kurimski; 10-12-2010, 11:15 AM.

              Comment


                #8
                Re: Track the computer where the user last logged on

                Scott,

                What Gary is getting at is that by using the index method, and doing a fetch_find(), there is no need to do a query. It would be redundant.

                tracking when they go offline would be in an on_exit or can_exit event. This is executed just before a5 closes.

                Tom

                Comment


                  #9
                  Re: Track the computer where the user last logged on

                  Please excuse me for jumping in here. I don't currently have experience tracking logged-in users (haven't created the code for it), but I may do so soon, and so this thread has given me great insight into the issues.

                  But I had planned to use a timer event to periodically check each logged-in user (the program would regularly "check in" and update its timestamp), and theoretically that would allow me to identify within a minute (or whatever timer interval I decided best) when somebody shuts down without logging off. And if the interval is long enough, it shouldn't slow anything down.

                  Does that/should that work? And wouldn't that be a possible aid in tracking current users? It seems reasonable to assume that if a user's login timestamp ("I'm still here!") hasn't been updated within the programmed interval, you can properly assume the machine is offline.
                  There are three kinds of people in the world: those who can count, and those who can't.

                  Comment


                    #10
                    Re: Track the computer where the user last logged on

                    Tom.

                    Thanks for clearing that up, I needed that.

                    Because of where I am running the code from I know I will only return one positive result, therefore I was able to shorten the code even more (Code Below).

                    Eric, For what it's worth....
                    I added an online field to my employee table and set its value during my logon and logoff scripts.

                    I am not that far yet although my intent is to eventually check if the last logon time was later than the last logoff time and set the status accordingly. To check accuracy I will build a function that runs on a single PC, loops the employee table, compare the timestamp fields and set the Emponline field accordingly.

                    I know there are a million ways to accomplish the same thing with varying points of accuracy although since I already have both of the timestamp fields I thought it would be worth testing.


                    DIM tbl as P
                    tbl = table.open("emp",FILE_RW_SHARED)

                    'Set the index for the find to use
                    tbl.index_primary_put("_Emplognid")

                    'Find the current user
                    tbl.fetch_find(gvuser)

                    tbl.change_begin()
                    'Set Emp - Emponline to True (Online)
                    tbl.emponline = .T.

                    'Set Emp - Emplastpc to the computername of the user currently logging on.
                    tbl.emplastpc = api_getmachinename()

                    'Timestamp Emp - Emplaston
                    tbl.emplaston = now()
                    tbl.change_end(.T.)
                    Last edited by Scott Kurimski; 10-12-2010, 03:25 PM.

                    Comment


                      #11
                      Re: Track the computer where the user last logged on

                      I am curious do you timestamp when the user logs off also? How do you track when they go offline/logout? What happens if they just close the app, how does it track their logout?
                      Look at autoexec script, the last function call
                      Code:
                      on_database_exit(code)
                      The comments are my native language � sometimes mixed with english and many scribal errors � sorry.
                      So the on_database_exit() function register the code that will be executed when the current database is closed.
                      http://wiki.alphasoftware.com/on_dat...xit%20Function
                      The logout code is above on_database_exit() function, look at the string between the tags %code%.
                      We use this user trapping about 3 month without any problems. Attention to violation of a law � you must not collect users work habits without any general information to all employed.

                      It is forbidden in our offices to switch of the computer, when not all programs have been closed. The linux server doesn�t like this. It happened time to time and sometimes Excel or Open Office files quit the work and get corrupted. The IT has no chance to catch these users. My logging report will show, who forgot to log out.

                      Cornelius

                      Comment


                        #12
                        Re: Track the computer where the user last logged on

                        This may be exactely what I am looking for. Basically if the user clicks the Windows close icon I want to run my log off function.

                        Do I understand this correctly......anything in between Code = <<%code% and %code% will fire when the Windows Red X is selected although does not work when the application is closed via the task manager?

                        Comment


                          #13
                          Re: Track the computer where the user last logged on

                          Do I understand this correctly......anything in between Code = <<%code% and %code% will fire when the Windows Red X is selected although does not work when the application is closed via the task manager?
                          Yes, it works even the Windows Red X is selected,
                          if you shoot down the computer (reset button, task manager or short circuit) the user remains online, even s/he is not.

                          Thought ahead, A5 could look for such error situation and send a e-mail to IT manager or / and user.

                          Now I found an other version of my autoexec script, so please replace it from my sample who_online.zip

                          Code:
                          dim global vRechner as c
                          dim global vUser as c
                          dim global vVersion as c
                          vRechner = api_getmachinename()
                          vUser = api_getusername()
                          vVersion = a5_getappversionnumber()
                          
                          'script initialised by function on_database_exit
                          dim code as c
                          
                          'who is and who is log s
                          dim tbl as p
                          dim tbl_log as p
                          dim qry as p
                          dim who_is as c
                          dim filter as c
                          dim nrec as n
                          
                          'make a string as required for logging information
                          'am Rechner = at computer
                          who_is = a5_eval_expression("=Var->vUser + \" am Rechner \" + Var->vRechner",local_variables())
                          
                          'open table
                          tbl = table.open("who_is")
                          'filter to find the user / computer 
                          filter = replace_parameters("who_is->Who_Is = [varC->who_is]", local_variables())
                          query.filter = filter
                          qry = tbl.query_create()    
                          nrec = qry.records_get()
                          
                          'who is 
                          if nrec = 1 then
                          	'found one, change record 
                          	tbl.change_begin()
                          	tbl.Who_is = who_is
                          	tbl.Online = .t.
                          	tbl.Stamp = now()
                          	tbl.change_end()
                          else
                          	'get a new one
                          	tbl.enter_begin()
                          	tbl.Who_is = who_is
                          	tbl.Online = .t.
                          	tbl.Stamp = now()
                          	tbl.enter_end()
                          end if
                          tbl.close()
                          
                          'who is logfile
                          tbl_log = table.open("who_is_log")
                          tbl_log.enter_begin()
                          tbl_log.Who_is = who_is
                          tbl_log.Online = .t.
                          tbl_log.Stamp = now()
                          tbl_log.enter_end()
                          tbl_log.close()
                          
                          '------------- autoexec end  ------
                          
                          'below the script for Database_on_exit
                          Code = <<%code%
                          dim tbl as p
                          dim tbl_log as p
                          dim qry as p
                          dim who_is as c
                          dim filter as c
                          dim nrec as n
                          
                          who_is = a5_eval_expression("=Var->vUser + \" am Rechner \" + Var->vRechner",local_variables())
                          tbl = table.open("who_is")
                          'filter to find the user / computer 
                          filter = replace_parameters("who_is->Who_Is = [varC->who_is]", local_variables())
                          query.filter = filter
                          qry = tbl.query_create()    
                          nrec = qry.records_get()
                          
                          if nrec = 1 then
                          	tbl.change_begin()
                          	tbl.Who_is = who_is
                          	tbl.Online = .f.
                          	tbl.Stamp = now()
                          	tbl.change_end()
                          else 'unwahrscheinlich, aber wenn versehentlich gel�scht wurde, dann neu anlegen
                          	tbl.enter_begin()
                          	tbl.Who_is = who_is
                          	tbl.Online = .f.
                          	tbl.Stamp = now()
                          	tbl.enter_end()
                          	
                          end if
                          tbl.close()
                          
                          'who is logfile
                          tbl_log = table.open("who_is_log")
                          tbl_log.enter_begin()
                          tbl_log.Who_is = who_is
                          tbl_log.Online = .f.
                          tbl_log.Stamp = now()
                          tbl_log.enter_end()
                          tbl_log.close()
                          %code%
                          
                          'Wenn Datenbank bereits gelossen ist, dann diesen Code ausf�hren
                          'when the database has been closed, than start this last script
                          on_database_exit(code)
                          Cornelius

                          Comment


                            #14
                            Re: Track the computer where the user last logged on

                            Corelius,

                            Thank-you for your help. I ended up using the on_database_exit function and added this to my autoexec which did the trick. The App_Exit_YourAppName will run your logoff routines (or whatever) if the user clicks the Windows application close button (Red X). Thanks again.

                            Code = <<%code%
                            App_Exit_YourAppName()
                            %code%
                            on_database_exit(code)

                            Comment

                            Working...
                            X