Identifying the user

We are in a Windows95 environment and I would like to create an application that will identify the user by his/her PC name.  Could someone assist me with this.  Please provide the source code and any Declarations that are required.
-Thanks
TWilbertAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
One simple method is:

Add a Microsoft Winsock control to your project, place it on a form, add a command button to the form and paste the following code:

Private Sub Command1_Click()
    MsgBox (Winsock1.LocalHostName)
End Sub

There are obviously overheads associated with extra controls, however in this case it may be that the ease of use outweighs this.
0
ryanvsCommented:
There are two functions which you might find useful:

Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long


Use them by doing the following

Dim strResult As String
Dim lResult As Long

strResult = String$(128, 0)
lResult = GetComputerName(strResult, 128)
strResult = Left$(strResult, lResult)


Do the same thing for GetUserName.
Good Luck.
0
TWilbertAuthor Commented:
Your solution appears to partially work.  Why does lResult equal 1?  It causes strResult to hold only the first character of the computer name.
0
ryanvsCommented:
Sorry, my mistake.  Some API calls return the length of the string as a result, but these two do not.  The answer is simple, though.

Public Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long


Dim strResult As String
Dim lResult As Long

' Get the Computer Name
strResult = String$(128, 0)
lResult = GetComputerName(strResult, 128)
' Check lResult <> 0 if you want to see if GetComputerName succeeded...

' Remove extra characters
lResult = lstrlen(strResult)
strResult = Left$(strResult, lResult)


Good Luck.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TWilbertAuthor Commented:
Thanks for your assistance ryanvs.  It worked like a charm.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.