Click to See Complete Forum and Search --> : GetComputerName() function


CecileR
August 31st, 2001, 04:18 AM
Why is my program doesn't recognize the function
GetComputerName()? Do I need to include some dll for these to run?

Please help.
Thanks.

cecile


The more u read, the more u do not know

berta
August 31st, 2001, 04:25 AM
GetComputerName is an API function
U must declare in declaration zone...

public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long




<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

phunkydude
August 31st, 2001, 04:30 AM
The function is part of the API try this:
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long


Note also that there are returned parameters, so you would eventually get the computername from left$(sBuffer,lSize).

HTH

Cimperiali
August 31st, 2001, 06:56 AM
'from api-guide (a free tool!)
'Requires Windows NT 3.1 or later; Requires Windows 95 or later
'The GetComputerName function retrieves the computer name of the current
'system.
'This name is established at system startup, when it is initialized from the
'registry
'copy paste this in a form code, or change the api declaration to public
'to use it from a .bas module
private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (byval lpBuffer as string, nSize as Long) as Long
private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim strString as string
'Create a buffer
strString = string(255, Chr$(0))
'get the computer name
GetComputerName strString, 255
'remove the unnecessary chr$(0)'s
strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
'Show the computer name
MsgBox strString
End Sub





Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater