To Track Logon and Logoff time

Posted by Pandi_Cenza under VB.NET on 12/10/2013 | Points: 10 | Views : 3097 | Status : [Member] | Replies : 15
Hello Friends,

Any one send the coding for to track Logon and logoff times in system using VB.net.




Responses

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer:-
http://www.codeproject.com/Articles/1314/Tracking-users-login-logout-times-on-your-site
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6a5bd9fb-79f7-4a1e-bdc6-394113930091/getting-system-shutdown-start-logoff-logon-and-lock-details-on-a-particular-date

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also visit:-
http://stackoverflow.com/questions/15314646/limiting-the-time-in-and-time-out-in-a-day-in-vb-net
http://aspnetvisual.blogspot.in/2011/11/how-to-capture-logoff-time-when-user.html

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
I am already tried what you have sent the link page. But, no results. my main objective is to track, how many times my operators using their system Login and Logoff.

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
In this case, You can create History table, and everytime you log-in/logoff to the system,insert 1 entry into history table.

So that you can track your log-in and log-off time.

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
Yes, I am accepting your points. I am writing the program and update the Database. My doubt or problem is how execute my program when the user log-in and log-off. Is it any API function available to call when user log-in and log-off?

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
No,simply create an History table, once user logs-in,then in global.asax file,write your insert dml statement, on the login-button,if user successfully logs-in,then inside log-in button,write your insert statement code.

once log-out,on click of log-out button,again write insert statement

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
Hello Friend, i am not familiar in asp.net. could you explain in VB.net? if possible send the coding (i.e. whenever user login their system i can store the date & time after that i will update my DB)

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Write inside login_button event as,

//once user logs-in CODE FOR LOGIN
protected void btn_login()
{
string sql_query = "select count(*) from login_info where user_name = '"+ txt_user_name.Text +"'";
sqlconnection con = new sqlconnection("your connection string");
sqlcommand cmd = new sqlcommand(con);
cmd.commandtext = sql_query;
object count = cmd.executescaler();
count = convert.toint32(count);

//store user name into Session for Logout purpose
Session["user_name"] = txt_user_name.Text;

if(count>0) //means user exists in database
{
//Then insert Log-in entry for user
sql_query = "insert into login_info_history(user_name,login_time) values('"+ txt_user_name.Text +"',getdate())";
cmd = new sqlcommand(con);
cmd.commandtext = sql_query;
cmd.executenonquery();
}
}


//and once user click on log-out button,write CODE FOR LOGIN
protected void btn_logout()
{
string sql_query = "insert into login_info_history(user_name,log_out_time) values('"+ Session["user_name"] +"',getdate())";
cmd = new sqlcommand(con);
cmd.commandtext = sql_query;
cmd.executenonquery();
}



Hope this helps you.

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Pandi_Cenza,

Did you find post. I have explain the things you want.

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply and coding. I want the user whenever log-in the computer, the time saved in database and the same whenever the user log-off computer the time stored in Database. how i know the user log-in the time my coding will update the database?

Example - I log-in my system morning 8 clock, my in-time stored in DB as well as i log-off the system afternoon 1 pm, my log-off time stored in DB

Hope this is clear. if any doubts please help me.

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
So,in that case, instead of taking getDate() take Corrent_Timestamp(), it will have date_time

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,you can extract Time from date as

Select RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) as Time
Select RIGHT(CONVERT(VARCHAR, current_timestamp, 100),7) as Time

It will give you only time.

Replace above code with getdate() inside insert statement.

and let me know

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
Sorry friend, still you not understand my requirement.

i want the following

a) Username
b) System No
c) Last log-in date time
d) Last Log-Off date time

Your last post says current date taken from my-sql database

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
Friend,

I have around 25 system on my network and I have to create a program to track login time, logout time, lock time and unlock time. thanks.

Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandi_Cenza on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down


Select RIGHT(CONVERT(VARCHAR, GETDATE(), 100),7) as Time (my question how can i take last login date from here)
Select RIGHT(CONVERT(VARCHAR, current_timestamp, 100),7) as Time (my question how can i take last login date from here)



Pandi_Cenza, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response