Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting hostname of pc using vbscript

Status
Not open for further replies.

kirk124

Programmer
Apr 15, 2003
26
US
Hi

Does anyone know a way in vbscript to get the hostname of a pc. I know you can execute "ipconfig -all" on command line
but I want to do it it vbscript.

Also is there a way to find if the printer connected to my pc is a local or a network printer
 
Here is the script for you printer problem, it will give you more information as well :)

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each objItem in colItems
Wscript.Echo "Attributes: " & objItem.Attributes
Wscript.Echo "Availability: " & objItem.Availability
Wscript.Echo "Capabilities: " & objItem.Capabilities
Wscript.Echo "CapabilityDescriptions: " & objItem.CapabilityDescriptions
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
Wscript.Echo "CurrentCapabilities: " & objItem.CurrentCapabilities
Wscript.Echo "Default: " & objItem.Default
Wscript.Echo "DefaultCapabilities: " & objItem.DefaultCapabilities
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "Direct: " & objItem.Direct
Wscript.Echo "DriverName: " & objItem.DriverName
Wscript.Echo "ExtendedPrinterStatus: " & objItem.ExtendedPrinterStatus
Wscript.Echo "InstallDate: " & objItem.InstallDate
Wscript.Echo "Local: " & objItem.Local
Wscript.Echo "Location: " & objItem.Location
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Network: " & objItem.Network
Wscript.Echo "PortName: " & objItem.PortName
Wscript.Echo "ServerName: " & objItem.ServerName
Wscript.Echo "Shared: " & objItem.Shared
Wscript.Echo "ShareName: " & objItem.ShareName
Wscript.Echo "SystemName: " & objItem.SystemName
Next
 
here is how you get the machine name using WMI


On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
Wscript.Echo "Machine Name: " & objItem.CSName
Next
 
This must be much easier.

Set WshNetwork = WScript.CreateObject("WScript.Network")

WScript.Echo "Computer Name: " & WshNetwork.ComputerName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top