How to obtain a computer name? 
Author Message
 How to obtain a computer name?

How can i obtain the name of the computer where my program is running?


Tue, 24 Aug 2004 09:04:26 GMT  
 How to obtain a computer name?
Hi, I was also looking for help for that too last few weeks and I finally
got help from one of the newgroup reader. Below I paste the function for
your reference:

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

Public Function ComputerName() As String
'This function will return the name of the computer where this program
resides.
    Dim sPCName As String

    'Allocate some space to the string
    sPCName = Space(250)

    'Call api to get computername
    GetComputerName sPCName, Len(sPCName)

    'Remove unused characters
    sPCName = Left(sPCName, InStr(sPCName, vbNullChar) - 1)

    ComputerName = sPCName
End Function
****************************

Thanks for Darren for sharing this with me, and now I can share it with you.
:)

JJ.


Quote:
> How can i obtain the name of the computer where my program is running?



Tue, 24 Aug 2004 14:34:45 GMT  
 How to obtain a computer name?

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

Public Function Get_Computer_Name() As String

Dim strName As String, lngLen As Long

strName = "                       "

lngLen = Len(strName)

If GetComputerName(strName, lngLen) = False Then

    Get_Computer_Name = ""

Else  
    Get_Computer_Name = Mid$(strName, 1, lngLen)
End If

End Function

Quote:
>-----Original Message-----
>How can i obtain the name of the computer where my
program is running?

>.



Tue, 24 Aug 2004 21:38:58 GMT  
 How to obtain a computer name?

Quote:
>-----Original Message-----
>How can i obtain the name of the computer where my
program is running?

>.

Try this
declare a public variable in a module

Public Retval

Quote:
>'

'
' ---------------------------------------------------------
------
'.. GetComputerName retreives computer user is running app
from
' ---------------------------------------------------------
------
'
Public Declare Function GetComputerName Lib "Kernel32"
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
'

then call this in the forms main event or click event on a
button

retval = GetComputerName(pcname, 255)



Sat, 28 Aug 2004 02:51:07 GMT  
 How to obtain a computer name?
Thanks to all of you guys.. Sorry for this late reply, been busy the week.


Quote:
> How can i obtain the name of the computer where my program is running?



Sat, 28 Aug 2004 16:32:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to obtain local network NetBIOS computer names?

2. Obtaining Computer Name

3. Obtaining the name of the remote computer connecting to Terminal Services

4. how can I obtain all names of computers from workgroup

5. Obtaining table names/field names from Access @ runtime

6. Get computer name and IP from remote computer

7. LDB Viewer -- Need to get NT user login name in addition to computer name

8. retreiving the computer login name and machine name

9. Computer Name, Exe Name, and Exe Path

10. NEWBIE - How to get computer name or user name

11. Getting the user's logon name and computer name

12. User name form computer name ??

 

 
Powered by phpBB® Forum Software