Link to home
Start Free TrialLog in
Avatar of MatthiasK
MatthiasK

asked on

Resolve ComputerNames in VB

How can I resolve my Computername in VB4 ?
The answer what I got from vbwayne is for for the current login
name not the Cname.
Avatar of adityau
adityau

Use GetComputerName API
Here is some code you can use:

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const MAX_COMPUTERNAME_LENGTH = 15
Function GetComputerNameAPI() As String
    Dim Buffer As String * MAX_COMPUTERNAME_LENGTH
    GetComputerName Buffer, MAX_COMPUTERNAME_LENGTH
    GetComputerNameAPI = Trim(Buffer)
End Function

Private Sub Command1_Click()
    MsgBox GetComputerNameAPI()
End Sub

/Hope it helps
/Korky le petit mongole
Avatar of MatthiasK

ASKER

Hi korky,
thanks, this is general working but for some reasons only on NT plattforms, not WIN95 ?!
In VB6, thus I think in VB4 too, you can use the Winsock control to get the local host name.

If that's sufficient, here's how to do it :

Create a form, add the Winsock control to your toolbox, drag one onto your form and add this code to the click event of a commandbutton :

Private Sub Command1_Click()
    MsgBox Winsock1.LocalHostName
End Sub

Maybe this gets around your Win95 problem.
Thats cool and works, where can I found out more about winsock objects ??
MSDN!?
I think there's enough documentation on it in the Help or MSDN.

Basically, it's used for other things than this, but ... it's a feature you can use for some other stuff too.

Winsock is mostly used in Internet applications, maybe you can find books on that ("Developing Internet applications with VB")

Korky : thanks for answering on my comment ...
vindevogel: I'm kind of new around here, is there a difference?
Yes there is ...

You answered a question, thus locking it for other users.  Most posters and users don't really appreciate that, but well ... (Nobody else looks at it anymore because it's answered)


Your answer was right, but didn't help Matthias, because he had a problem with Win95.

I suggested something, that worked out fine for him.

You answered again, locking the question again.

Matthias can only accept your answer (since I can't answer).  He can therefore only award points to you, even if he wants to give them to me for solving his problem.  

When you "suggest" something, you post it as a comment.  When you're sure of your answer, you post it as an answer.
Moreover, the poster will generally ask to "answer" the question when he resolved his problem.  He can then choose between the people who gave him answers.

Not that I'm so keen on the points, but I like to get credit for what I post.  I take pride in my grades and points.  Just like I take pride in the software I write.  It's a business mentality, I guess.

Yves
sorry!
MatthiasK: can you please reject my answer
I'm also new here, how can I pass this points to vindevogel ?
I think you must way until he gives you an other answer...
ASKER CERTIFIED SOLUTION
Avatar of vindevogel
vindevogel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Capitalistic, ain't it?
Hey, I live in Belgium ...  ;-)

Here, it's perfectly normal and accepted to be a bit capitalistic.

It's even perfectly normal to take bribes, some politicians seem to think.

Bon, ok!
Ciao ma poule!
you can click where it says accept as comment also MatthiasK ... should be right near any of the comments.  So just look for one of vindevogels comments ... and click it
ThaSmartUno: you're right ... I'm still stuck with the old interface of this site.