I know my user name but how read it in source (if you know answer, please write (source) in VB). My OS is Windows 2000.
TNKS!
Printable View
I know my user name but how read it in source (if you know answer, please write (source) in VB). My OS is Windows 2000.
TNKS!
Code:Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub Main()
Dim str_Data As String * 25
Call GetUserName(str_Data, Len(str_Data))
MsgBox Left(str_Data, InStr(str_Data, Chr(0)) - 1)
End Sub
WORK!
Thank You!
Here's a real simple app I wrote to see who was using my computer at work:
I put it in the run key in the registry and it runs when you first boot/login. It logs the dateCode:'Form1 visible property is false
Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Private Sub Form_Load()
Dim s As String
Dim cnt As Long
Dim dl As Long
Dim CurUser As String
cnt = 199
s = String$(200, 0)
dl = GetUserName(s, cnt)
If dl <> 0 Then CurUser = Left$(s, cnt) Else CurUser = ""
Open "c:\windows\whoson.log" For Append As #1
Print #1, CStr(Now) & ", User: " & CurUser
Close #1
Unload Form1
Set Form1 = Nothing
End Sub
and time and the users login name.
:oEditting: Forgot the Set statement
[Edited by dsy5 on 11-11-2000 at 01:24 PM]