Here is a small code sample using WScript to get the computer name, in addition to members of the ServerVariables collection for returning the domain name entered in the browser and the IP of the server.
<% Set pc = CreateObject("Wscript.Network") response.write pc.ComputerName Set pc = nothing response.write " (currently connected as " response.write ucase(Request.ServerVariables("SERVER_NAME")) response.write " on " response.write Request.ServerVariables("LOCAL_ADDR") & ")" %> |
Of course, you may want the actual computer name (from system properties), not the server name as requested through a web server (which could be an IP address, or an alias, or a fully qualified domain name). So, you can use WMI:
<% Set Loc = createobject("WBEMScripting.SWBEMLocator") Set nms = Loc.ConnectServer() WQL = "SELECT CSName FROM Win32_OperatingSystem" Set cs = nms.ExecQuery(WQL, "WQL", 48) For Each pc In cs Response.Write pc.CSName Next set cs = nothing: set nms = nothing: set loc = nothing %> |
And here is a sample for getting the name of a SQL Server machine:
<% set conn = CreateObject("ADODB.Connection") conn.open "<connectionString>" set rs = conn.execute("SELECT @@SERVERNAME") response.write rs(0) rs.close: set rs = nothing conn.close: set conn = nothing %> |