Get the computer name via the IP address

set WMI = GetObject("winmgmts:\\" & ip & "\root\cimv2")

if Err.Number <> 0 then
    msgbox Err.Description
end if

set items = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")
for each item in items
    msgbox item.Name
next

Running the script on behalf of the user gets the host name, and running on behalf of the system returns the error

Permission denied 70

What other way can I get the name of a remote computer?

Author: Doofy, 2019-04-04

2 answers

Since AD is used, I suggest using the domain controller audit log as the source for creating the workstation database. Here is an example of the information from the record (EventID=4624 / login) that occurs when the domain workstation loads and attempts to contact the domain controller (based on W2K8).

    Имя учетной записи:     COMPUTER0$
    Домен учетной записи:       DOMAIN-A
    Код входа:      0x316d2639
    GUID входа:     {47f539ad-1ea8-a704-b23f-c5f7d3bcf80d}

Сведения о процессе:
    Идентификатор процесса:     0x0
    Имя процесса:       -

Сведения о сети:
    Имя рабочей станции:    
    Сетевой адрес источника:    192.168.1.170

As you can see from the text, the station name is available (with the added symbol $ at the end). And the most necessary thing is the IP address of the node that I communicated with the domain controller.

Next is a matter of technique:

  1. Use a technical account with local domain controller administrator rights to read Security log entries

  2. Parse the XML data of the log entries.

  3. Set the name and IP match, and enter it in the database.

P.S. An alternative solution would be to raise the WINS service, which runs in automatic mode, virtually no configuration required. But, if my memory serves me correctly, this service has major vulnerabilities, up to RTE.

Or still configure the DNS service correctly. So that the reverse names are correctly registered in the DNS database.

 1
Author: Daemon-5, 2019-07-29 07:24:59

In Active Directory, I added a group member to Domain Admins, but he has access to the remote desktop. The script is run from the system, the connection comes from the user.

set locator = CreateObject("WbemScripting.SWbemLocator") 
set WMI = locator.ConnectServer(ip, "root\cimv2", "User", "Password")

So far, I have solved the problem in this way, but I will be happy with any other options.

 0
Author: Doofy, 2019-04-04 15:43:50