|
-
Jan 24th, 2005, 06:07 AM
#1
Thread Starter
New Member
reading the loginname
Hi,
I want to know that is this possible to read the user which has logged in on a windows machine from a VB6.0 application.For ex.there is a user named jeff who logs in ,I want my application to create a read only text file named jeff.txt mentioning the time when he logged in and logged out.The data should be appended to this file everytime jeff logs in and logs out.
manish
-
Jan 24th, 2005, 06:12 AM
#2
Frenzied Member
Re: reading the loginname
i know there is an api call to check the name of the person currently logged in. check allapi.net to get the username. once u have done that, what you can do is make the program invisible, put it up in startup items for all users, and in the form_unload you can add the logout time and save the login time and logout time.
-
Jan 24th, 2005, 06:18 AM
#3
KING BODWAD XXI
Re: reading the loginname
VB Code:
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
From API GUIDE
VB Code:
'This project needs a timer
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
Timer1.Interval = 100
Timer1.Enabled = True
Dim strTemp As String, strUserName As String
'Create a buffer
strTemp = String(100, Chr$(0))
'Get the temporary path
GetTempPath 100, strTemp
'strip the rest of the buffer
strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1)
'Create a buffer
strUserName = String(100, Chr$(0))
'Get the username
GetUserName strUserName, 100
'strip the rest of the buffer
strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
'Show the temppath and the username
MsgBox "Hello " + strUserName + Chr$(13) + "The temp. path is " + strTemp
End Sub
Private Sub Timer1_Timer()
Dim Boo As Boolean
'Check if this form is minimized
Boo = IsIconic(Me.hwnd)
'Update the form's caption
Me.Caption = "Form minimized: " + Str$(Boo)
End Sub
HTH
-
Jan 24th, 2005, 07:07 AM
#4
Re: reading the loginname
Once you have the username
VB Code:
Open "c:\loginfile.txt" For Append As #1
Print #1, username & " logged in at: " & Now
Close #1
Bare in mind that the GetUserName API acts differently if you are running Win2000 or XP.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|