在本地Intranet上获取计算机名称

We have written a code that shows the computer's name and IP in an php page for our local intranet so our User Services can ask the end users their computer name. It currently runs only in IE and only when the file is on the local computer.

<script type="text/javascript" language="javascript">           
    var cpu = new ActiveXObject("WScript.Network");
    document.write("<h1 style=\"color:#ffc533\"> Your Computer's name is: " + cpu.ComputerName + "</h1>")
</script>
<h1>Your IP Address is: <?php print $_SERVER[REMOTE_ADDR] ?></h1>

When we test it on the computer both show but when we upload it to the server it displays only the IP Address. Working only in IE is not a problem, however, the local issue is. So my question is two fold. How can I get the computer name to display on the page or is there a better way to get it to work without having reverse DNS enabled?

EDIT BEGIN

Original answer is below, I added this as an alternative to opening security wholes.

You could write your own ActiveX DLL and register it on each client computer. Have it implement a class that returns the computer name, or you could even just wrap WScript.Network. Then, implement the IObjectSafety Interface in your class and mark it as safe for scripting. The WScript object is unsafe because it can also modify files on the computer, but if you only wrap the single function to retrieve the computer name, then your control won't be able to modify any files.

To make it safe for scripting in your implementation for IObjectSafety have SetInterfaceSafetyOptions return S_OK for IID_IActiveScript, IID_IDispatch, and IID_IPersist. See the provided links for implementation details.

This is more work, but removes the hazard of showing users how to run unsafe controls with the below options.

EDIT END

On each client machine:

Open the Internet Explorer and select the Tools->Internet Options menu:

1

Select the Security Tab and press the Custom level button:

2

Ensure that under the ActiveX controls and plug-ins section the two settings Download unsigned ActiveX controls and Initialize and script ActiveX controls not marked as safe for scripting are set to Prompt:

3

Press OK on both dialog boxes to close them.

Also, to ensure the Scripting Runtime (WScript) is registered, go to the Start Menu and press Run, type “cmd” and press enter:

4

A command prompt should open:

Ensure the drive is drive C, type “C:”

Copy and paste “regsvr32 C:\windows\system32\scrrun.dll” and press enter. Ensure a message box appears saying DllRegisterServer succeeded:

5

Setup complete.