Solved

VBScript: check the computer name

Posted on 1999-01-10
1
996 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now