Solved

VBScript: check the computer name

Posted on 1999-01-10
1
1,015 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 79
VBA/SQL - Connect to SQL server and pull data 4 89
VBA: Select SQL query based on a config Sheet v2 11 38
vbModal 12 38
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

25 Experts available now in Live!

Get 1:1 Help Now