VBScript Scripting Techniques > Network > Names > Host Name
| Registry (WSH Shell) | |
|---|---|
| VBScript Code: | |
|
Set wshShell = CreateObject( "WScript.Shell" ) strRegValue = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname" strHostName = wshShell.RegRead( strRegValue ) WScript.Echo "Host Name: " & strHostName |
|
| Requirements: | |
| Windows version: | NT 4, 2000, XP, Server 2003, or Vista |
| Network: | TCP/IP |
| Client software: | Windows Script 5.6 for Windows NT 4 (no longer available for download?) |
| Script Engine: | WSH |
| Summarized: | Works in Windows NT 4 or later, requires a TCP/IP network, works with CSCRIPT.EXE or WSCRIPT.EXE only. Will require Windows Script 5.6 for Windows NT 4 to make it work in NT 4 (no longer available for download?). |
| [Back to the top of this page] | |
| Registry (WMI StdRegProv) | |
| VBScript Code: | |
|
Const HKEY_LOCAL_MACHINE = &H80000002 strRegKey = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv" ) objReg.GetStringValue HKEY_LOCAL_MACHINE, strRegKey, "Hostname", strHostname WScript.Echo "Host Name: " & strHostName |
|
| Requirements: | |
| Windows version: | ME, 2000, XP, Server 2003, or Vista (95, 98, NT 4 with WMI CORE 1.5) |
| Network: | TCP/IP |
| Client software: | WMI CORE 1.5 for Windows 95, 98 or NT 4 |
| Script Engine: | any |
| Summarized: | Can work on any Windows computer, but
WMI CORE 1.5 is required for Windows 95, 98 or NT 4. Can be used in *.vbs with CSCRIPT.EXE or WSCRIPT.EXE, as well as in HTAs. |
| [Back to the top of this page] | |
| System Scripting Runtime | |
| VBScript Code: | |
|
Set objIP = CreateObject( "SScripting.IPNetwork" ) strHostName = objIP.Hostname WScript.Echo "Host Name: " & strHostName |
|
| Requirements: | |
| Windows version: | any |
| Network: | TCP/IP |
| Client software: | System Scripting Runtime |
| Script Engine: | any |
| Summarized: | Works in any Windows version with System Scripting Runtime is installed, with any script engine. |
| [Back to the top of this page] | |
page last modified: 2025-10-16; loaded in 0.0045 seconds