Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get the Web server machine name using JavaScript

Posted on 2004-10-28
13
Medium Priority
?
3,482 Views
Last Modified: 2008-01-09
I can get the Machine Name of my Web server using VBScript with the following.

   Set WshNetwork = server.CreateObject("WScript.Network")
   MachinName=WshNetwork.ComputerName

How can I get this information using JavaScript?

0
Comment
Question by:BryanC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 12437928
var WshNetwork = new ActiveXObject( "WScript.Network" );
var MachinName = WshNetwork.ComputerName;

this won't work though for javascript. Default browser security probably won't let you create the activex object. And, even if it did, that would get the computer name of the client, not the server.

But like i said that probably won't work becuase of default browser security.

There is no way to get the name of the webserver from the client. YOu can pass it to the client from the server, but other than that your kinda stuck
0
 

Author Comment

by:BryanC
ID: 12438106
How can I pass it from the server to the client?
0
 
LVL 5

Expert Comment

by:jpontani
ID: 12438256
In your script code you could just write the value.

<script language="javascript" type="text/javascript">

....code....

var machineName = <%=MachinName%>

....code....

</script>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BryanC
ID: 12438335
I do not know much about JavaScript but I need to modify an existing file. It starts out with JavaScript.

<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma','no-cache')
Response.AddHeader('cache-control','no-store')
<!--#INCLUDE VIRTUAL='...'-->
<!--#INCLUDE VIRTUAL='...'-->
 
Is there some way to just call a VB function from within JavaScript that will return the Machine Name?
0
 
LVL 25

Expert Comment

by:devic
ID: 12439333
try this:
================
<script language="javascript" type="text/javascript">
    var machineName ="<%=Request.ServerVariables("SERVER_NAME")%>";
</script>
0
 
LVL 17

Expert Comment

by:mreuring
ID: 12442020
I suggest asking this question to be moved to the ASP section:
http://www.experts-exchange.com/Web/Web_Languages/ASP/

They will most likely be able to help you. From what I recall of those days, you can call and use any objects and/or variables across javascript and vb in the ASP-page, just as long as you realise that JavaScript is case-sensitive.

Hope it helps,

  Martin
0
 

Author Comment

by:BryanC
ID: 12445055
The suggestion by devic returns the server name supplied in the URL. However, this is the alias name of the Web server and not the actual server name.
We have two web servers, JcoPimWeb01 and JcoPimWeb01. We have an alias defined as JcoPimIIS01 and the users reference it in there URL so that when we need to work on the production web server we simply change the IP address of the alias and the users continue to use the same URL.

MachineName = "<%=Request.ServerVariables('"SERVER_NAME")%>";  
Returns alias name (JcoPimIIS01).

Set WshNetwork = server.CreateObject("WScript.Network")
MachinName=WshNetwork.ComputerName
Returns actual machine name (JcoPimWeb01).

Is there a call that will return the actual machine name?

Thanks,
Bryan
0
 
LVL 6

Expert Comment

by:boblah
ID: 12505365
You are actually using serverside javascript, which is causing some confusion.

The code you want is:

var WshNetwork = server.CreateObject("WScript.Network");
var MachinName = WshNetwork.ComputerName;
0
 

Author Comment

by:BryanC
ID: 12505996
boblah

This does not seem to work. With the following code I get the "test1" message but nothing else.

alert("test1")
var WshNetwork = server.CreateObject("WScript.Network");
var MachinName = WshNetwork.ComputerName;
alert(MachinName);
alert("test2")
0
 
LVL 6

Expert Comment

by:boblah
ID: 12507162
try

<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma','no-cache')
Response.AddHeader('cache-control','no-store')
var WshNetwork = server.CreateObject("WScript.Network");
var MachineNameServerSide = WshNetwork.ComputerName;

%>

Machine name = <%=MachineNameServerSide %>

<script LANGUAGE="JavaScript">
<!--
var MachineNameClientSide = '<%=MachineNameServerSide %>';
-->
</script>

<input type="button" onclick="alert('Machine name of the server is ' + MachineNameClientSide);" />

0
 

Author Comment

by:BryanC
ID: 12507362
I get the following error:

Error Type:
Microsoft JScript runtime (0x800A1391)
'server' is undefined
/web21/pfdFreePlot_LBC.asp, line 7
0
 
LVL 6

Accepted Solution

by:
boblah earned 2000 total points
ID: 12507386
ok, it's probably a case sensitive thing, so try:

<%@ Language=JavaScript %>
<%
Response.Expires = -1
Response.AddHeader('Pragma','no-cache')
Response.AddHeader('cache-control','no-store')
var WshNetwork = Server.CreateObject("WScript.Network");
var MachineNameServerSide = WshNetwork.ComputerName;

%>

Machine name = <%=MachineNameServerSide %>

<script LANGUAGE="JavaScript">
<!--
var MachineNameClientSide = '<%=MachineNameServerSide %>';
-->
</script>

<input type="button" onclick="alert('Machine name of the server is ' + MachineNameClientSide);" />

0
 

Author Comment

by:BryanC
ID: 12508551
boblah  

Thank you. This works.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question