4 Replies - 735 Views - Last Post: 04 December 2014 - 08:59 AM Rate Topic: -----

#1 Y625   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-December 14

VB.NET code that will count the time you've been online

Posted 04 December 2014 - 05:35 AM

VB.NET code that will count the time you've been online at a particular website
Is it possible? :o

I don't know where to start
HELP PLEASE :surrender:

Is This A Good Question/Topic? 0
  • +

Replies To: VB.NET code that will count the time you've been online

#2 frazereastm   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 88
  • Joined: 03-December 14

Re: VB.NET code that will count the time you've been online

Posted 04 December 2014 - 06:11 AM

it would be easier if you made your own browser in vb but i'm guessing you dont want to do this?
do you want to store this information, add up the lengths of different sessions?
try explain what you are trying to do a little better
thanks =)
Was This Post Helpful? 0
  • +
  • -

#3 Y625   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-December 14

Re: VB.NET code that will count the time you've been online

Posted 04 December 2014 - 07:31 AM

View Postfrazereastm, on 04 December 2014 - 06:11 AM, said:

it would be easier if you made your own browser in vb but i'm guessing you dont want to do this?
do you want to store this information, add up the lengths of different sessions?
try explain what you are trying to do a little better
thanks =)


maybe creating a browser will be my last option for now :D

i was inspired by the android App - Checky that counts how many times you look at your phone
and now I want to make a version which can be use in a PC
my plan is that I want to record how long a user consumes his/her time on a website like Facebook in a day
then it will notify/alert the user when it exceeds the given time (set by the user) where he/she can only visit the website


sorry for poor explanation ...
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1538
  • View blog
  • Posts: 3,869
  • Joined: 01-February 13

Re: VB.NET code that will count the time you've been online

Posted 04 December 2014 - 08:35 AM

Hi,
If you use a .Net WebBrowser control on your form as frazereastm has mentioned, you would be able to track how long the user is on one site or another very easily.

However, if you are trying to get this information from the systems default browser such as IE, Firefox, Chrome, or any of them then you are going to have a little bit more work ahead of you.

There are 2 generic ways i can think of. The first would be to use the Process Class`s GetProcessesByName method to find any common browsers that are running. You will have to know the process names for all the common browsers in order to find them though. Such as my firefox process name is "firefox" so, to find any Firefox browsers you would do something like this.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim p() As Process = Process.GetProcessesByName("firefox")
        If p.Length > 0 Then
            For Each proc As Process In p
                MessageBox.Show(proc.MainWindowTitle)
            Next
        End If
    End Sub


I don`t know if you just want to see how long the browser is opened or how long certain websites have been viewed but, ether way, when a browser is found or a certain site name is found you would save the current date and time in a class scoped Date type variable.

When the process or site name is not found anymore then find the duration of time. You can do that by declaring a TimeSpan type variable and assigning it the current time (Now) minus the saved Date from when the browser or site was found.

The 2nd way is using the FindWindow and GetWindowText Win32 API functions in a Timer Tick event to do about the same thing but, you might as well stick with the .Net Process method.

There are a few other methods for IE and for Firefox for getting the actual url if that is what you want to detect. You can my examples of those at the links below.

Get browser all tabs url & close specific tab using VB.net 2008

Well, i could not find the link for the IE example so, here it is. You have to add a Reference to Microsoft Internet Controls to use the code.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each browser As SHDocVw.InternetExplorer In New SHDocVw.ShellWindows()
            MessageBox.Show(browser.LocationURL)
        Next
    End Sub



Now, with all that said, you will have a problem if they have more than one tab opened in the browser because, there will be no way to get all the urls from some browsers and the ones you can may have no option other than selecting each tab from your program to get each url. That would interrupt the user from doing whatever they where.

Hope some of this was helpful. :)

This post has been edited by IronRazer: 04 December 2014 - 08:44 AM

Was This Post Helpful? 0
  • +
  • -

#5 Y625   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-December 14

Re: VB.NET code that will count the time you've been online

Posted 04 December 2014 - 08:59 AM

mod: giant quote removed

wowowowow

thanks IronRazer :)/>
this is really a HUGE help

I hope I can finish this one.
i'll keep posted for my progress..

This post has been edited by modi123_1: 04 December 2014 - 09:23 AM
Reason for edit:: please do not quote the post above you.. use the 'reply' button or 'fast reply' box

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1