Sorry if this is a stupid question, but how can I return a win2000/xp
hostname?

I'm running a script that scans an IP range, then checks for OS + SP
compatibility before running a command against those computers meeting the
requirements. The ip addresses and results are logged to an excel file, but
as the pc's are on a dhcp network the log file soon becomes meaningless.

I assume it's possible to return the contents of a cmd window but this seems
to be an unnecessarily complicated route.

Thanks
Pete

RE: Hostname by KevinBuchanan

KevinBuchanan
Sun Jun 19 23:30:01 CDT 2005

Pete:

I recommend 1 thing...download "Scriptomatic" from the MS ScriptCenter...it
is the best tool for getting you started in the right direction.

Here is a script that I copied from the "Scriptomatic". Just use the
properties that you need. You can use the IP Address instead of the computer
name in the arrComputer array.

Also



On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("MISLT1", "splmhdc001", "sslmhnetsrv")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_OperatingSystem", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "BootDevice: " & objItem.BootDevice
WScript.Echo "BuildNumber: " & objItem.BuildNumber
WScript.Echo "BuildType: " & objItem.BuildType
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "CodeSet: " & objItem.CodeSet
WScript.Echo "CountryCode: " & objItem.CountryCode
WScript.Echo "CreationClassName: " & objItem.CreationClassName
WScript.Echo "CSCreationClassName: " & objItem.CSCreationClassName
WScript.Echo "CSDVersion: " & objItem.CSDVersion
WScript.Echo "CSName: " & objItem.CSName
WScript.Echo "CurrentTimeZone: " & objItem.CurrentTimeZone
WScript.Echo "DataExecutionPrevention_32BitApplications: " &
objItem.DataExecutionPrevention_32BitApplications
WScript.Echo "DataExecutionPrevention_Available: " &
objItem.DataExecutionPrevention_Available
WScript.Echo "DataExecutionPrevention_Drivers: " &
objItem.DataExecutionPrevention_Drivers
WScript.Echo "DataExecutionPrevention_SupportPolicy: " &
objItem.DataExecutionPrevention_SupportPolicy
WScript.Echo "Debug: " & objItem.Debug
WScript.Echo "Description: " & objItem.Description
WScript.Echo "Distributed: " & objItem.Distributed
WScript.Echo "EncryptionLevel: " & objItem.EncryptionLevel
WScript.Echo "ForegroundApplicationBoost: " &
objItem.ForegroundApplicationBoost
WScript.Echo "FreePhysicalMemory: " & objItem.FreePhysicalMemory
WScript.Echo "FreeSpaceInPagingFiles: " & objItem.FreeSpaceInPagingFiles
WScript.Echo "FreeVirtualMemory: " & objItem.FreeVirtualMemory
WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "LargeSystemCache: " & objItem.LargeSystemCache
WScript.Echo "LastBootUpTime: " &
WMIDateStringToDate(objItem.LastBootUpTime)
WScript.Echo "LocalDateTime: " &
WMIDateStringToDate(objItem.LocalDateTime)
WScript.Echo "Locale: " & objItem.Locale
WScript.Echo "Manufacturer: " & objItem.Manufacturer
WScript.Echo "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses
WScript.Echo "MaxProcessMemorySize: " & objItem.MaxProcessMemorySize
WScript.Echo "Name: " & objItem.Name
WScript.Echo "NumberOfLicensedUsers: " & objItem.NumberOfLicensedUsers
WScript.Echo "NumberOfProcesses: " & objItem.NumberOfProcesses
WScript.Echo "NumberOfUsers: " & objItem.NumberOfUsers
WScript.Echo "Organization: " & objItem.Organization
WScript.Echo "OSLanguage: " & objItem.OSLanguage
WScript.Echo "OSProductSuite: " & objItem.OSProductSuite
WScript.Echo "OSType: " & objItem.OSType
WScript.Echo "OtherTypeDescription: " & objItem.OtherTypeDescription
WScript.Echo "PlusProductID: " & objItem.PlusProductID
WScript.Echo "PlusVersionNumber: " & objItem.PlusVersionNumber
WScript.Echo "Primary: " & objItem.Primary
WScript.Echo "ProductType: " & objItem.ProductType
WScript.Echo "QuantumLength: " & objItem.QuantumLength
WScript.Echo "QuantumType: " & objItem.QuantumType
WScript.Echo "RegisteredUser: " & objItem.RegisteredUser
WScript.Echo "SerialNumber: " & objItem.SerialNumber
WScript.Echo "ServicePackMajorVersion: " &
objItem.ServicePackMajorVersion
WScript.Echo "ServicePackMinorVersion: " &
objItem.ServicePackMinorVersion
WScript.Echo "SizeStoredInPagingFiles: " &
objItem.SizeStoredInPagingFiles
WScript.Echo "Status: " & objItem.Status
WScript.Echo "SuiteMask: " & objItem.SuiteMask
WScript.Echo "SystemDevice: " & objItem.SystemDevice
WScript.Echo "SystemDirectory: " & objItem.SystemDirectory
WScript.Echo "SystemDrive: " & objItem.SystemDrive
WScript.Echo "TotalSwapSpaceSize: " & objItem.TotalSwapSpaceSize
WScript.Echo "TotalVirtualMemorySize: " & objItem.TotalVirtualMemorySize
WScript.Echo "TotalVisibleMemorySize: " & objItem.TotalVisibleMemorySize
WScript.Echo "Version: " & objItem.Version
WScript.Echo "WindowsDirectory: " & objItem.WindowsDirectory
WScript.Echo
Next
Next


Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" &
Mid(dtmDate,13, 2))
End Function






--

-Kevin


"Pete" wrote:

> Sorry if this is a stupid question, but how can I return a win2000/xp
> hostname?
>
> I'm running a script that scans an IP range, then checks for OS + SP
> compatibility before running a command against those computers meeting the
> requirements. The ip addresses and results are logged to an excel file, but
> as the pc's are on a dhcp network the log file soon becomes meaningless.
>
> I assume it's possible to return the contents of a cmd window but this seems
> to be an unnecessarily complicated route.
>
> Thanks
> Pete
>
>
>

Re: Hostname by James

James
Wed Jun 22 10:54:01 CDT 2005

"Pete" <xla760@at_efh-mail.com> wrote in message
news:d94kb2$jj8$1@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
> Sorry if this is a stupid question, but how can I return a win2000/xp
> hostname?
>
> I'm running a script that scans an IP range, then checks for OS + SP
> compatibility before running a command against those computers meeting the
> requirements. The ip addresses and results are logged to an excel file,
but
> as the pc's are on a dhcp network the log file soon becomes meaningless.
>
> I assume it's possible to return the contents of a cmd window but this
seems
> to be an unnecessarily complicated route.

Try something like this:

Set WMI = GetObject("winmgmts:\\" & IPAddress & "\root\cimv2")
For Each i in WMI.ExecQuery("Select * from Win32_ComputerSystem")
WScript.Echo i.Name
Next