Solved

VBScript: check the computer name

Posted on 1999-01-10
1
1,038 Views
Last Modified: 2012-05-04
I have a NT4 server (sp3 option pack) with IIS4.
I want to make a .ASP page with a script (VBScript) that can be able to get the computer name of a client (Windows98/95).

I use actually a script that can get the IP address. But i want to use my script with a DHCP server... so the IP is dynamical.
So i want to use now the computer name (to check the properties in a cooky).

Can someone help me ?
(i want to use an API like getcomputername from MS java classes).

Thanx
0
Comment
Question by:arnaudg
1 Comment
 
LVL 4

Accepted Solution

by:
chabaud earned 50 total points
ID: 1455208
You cannot call directly API call from VBscript, but you can use automation throught Server.Createobject("theprogid").

So you can get your client computer name from its IP address creating an activex DLL.

Here is an example wrote in VB5:

Option Explicit

Const WSADESCRIPTION_LEN = 256 + 1
Const WSASYS_STATUS_LEN = 128 + 1
Const AF_INET = 2
Const INADDR_NONE = &HFFFFFFFF

Private Type WSADATA
    wHighVersion As Long
    szDescription As String * WSADESCRIPTION_LEN
    szSystemStatus As String * WSASYS_STATUS_LEN
    iMaxSockets As Long
    iMaxUdpDg As Long
    lpVendorInfo As Long
End Type

Private Type HOSTENT
    h_name As Long 'LPSTR
    h_aliases As Long 'LPLPSTR
    h_addrtype As Integer
    h_length As Integer
    h_addr_list As Long 'char FAR * FAR * h_addr_list
End Type
       
Private Type IN_ADDR
    b1 As Byte
    b2 As Byte
    b3 As Byte
    b4 As Byte
End Type
               
Private Declare Function WSAStartup Lib "Wsock32.dll" (ByVal wVersionRequested As Integer, ByRef lpWSAData As WSADATA) As Long
Private Declare Sub WSACleanup Lib "Wsock32.dll" ()
Private Declare Function gethostbyaddr Lib "Wsock32.dll" (addr As Any, ByVal ilen As Long, ByVal itype As Long) As Long
Private Declare Function inet_addr Lib "Wsock32.dll" (ByVal cp As String) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, lpString2 As Any) As Long

Public Function GetName(cpAddr As String) As String
   
    Dim Adata As WSADATA
    Dim addr As Long
    Dim ptHost As Long
    Dim host As HOSTENT
    Dim buf As String * 256
   
    GetName = ""
   
    If WSAStartup(&H101, Adata) <> 0 Then Exit Function
   
    addr = inet_addr(cpAddr)
    If addr = INADDR_NONE Then Exit Function
   
    Dim saddr As IN_ADDR
    Dim b As Byte
    CopyMemory ByVal VarPtr(saddr), ByVal VarPtr(addr), 4
    b = saddr.b1
    saddr.b1 = saddr.b4
    saddr.b4 = b
    b = saddr.b2
    saddr.b2 = saddr.b3
    saddr.b3 = b
   
    ptHost = gethostbyaddr(ByVal VarPtr(saddr), 4, AF_INET)
   
    If ptHost <> 0 Then
        CopyMemory ByVal VarPtr(host), ByVal ptHost, 16
        lstrcpy buf, ByVal host.h_name
        GetName = Trim(buf)
    End If
   
    WSACleanup

End Function

INTO your ASP:

dim gcn
Set gcn = Server.Creatobject("GCN.GCN")
alert gcn.GetName("1.2.3.4")
Set gcn = Nothing

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question