Connecting Tech Pros Worldwide Help | Site Map

Get computer name

  #1  
Old July 20th, 2005, 01:01 PM
RR
Guest
 
Posts: n/a
I'm developing a web app and, for the user's convenience, I'd like to
display their local computer name (i.e. the name of the computer the browser
is running on).

I've looked very hard to find a script that will deliver this and I've also
tried some VBScript (which I know nothing about).

I found a script that did this:
var oShell = new ActiveXObject("Shell.Application");

then I thought to run
oShell.ShellExecute to echo %COMPUTERNAME%

But, I get a Permission Denied error.

How do I get the computer name? It's OK if the user has to grant permission
(I haven't found out how to get the Permission Denied to go away).

Thanks,
RR


  #2  
Old July 20th, 2005, 01:01 PM
RR
Guest
 
Posts: n/a

re: Get computer name


BTW, I want this to run in Internet Explorer.

thanks,
RR


  #3  
Old July 20th, 2005, 01:01 PM
Grant Wagner
Guest
 
Posts: n/a

re: Get computer name


RR wrote:
[color=blue]
> I'm developing a web app and, for the user's convenience, I'd like to
> display their local computer name (i.e. the name of the computer the browser
> is running on).
>
> I've looked very hard to find a script that will deliver this and I've also
> tried some VBScript (which I know nothing about).
>
> I found a script that did this:
> var oShell = new ActiveXObject("Shell.Application");
>
> then I thought to run
> oShell.ShellExecute to echo %COMPUTERNAME%
>
> But, I get a Permission Denied error.
>
> How do I get the computer name? It's OK if the user has to grant permission
> (I haven't found out how to get the Permission Denied to go away).
>
> Thanks,
> RR[/color]

var ax = new ActiveXObject("WScript.Network");
document.write(ax.UserName + '<br />');
document.write(ax.ComputerName + '<br />');

But you have to lower your security settings to dangerous and foolishly low
levels in the latest patched release of IE6SP1 to even get this to run.

If you insist on doing this, go to Tools -> Internet Options -> Security tab ->
Internet Zone -> Custom Level...

Change "Initialize and script ActiveX controls not marked as safe" to either
"Prompt" or "Enable"

A better choice might be:

Tools -> Internet Options -> Security tab -> Trusted sites Zone -> Sites...

Enter the domain name of the site you'd like the script to run from in the "Add
this Web site to the zone:" text box and click "Add". If the site is not https:,
you'll need to uncheck the "Require server verification (https:) for all sites
in this zone" checkbox before clicking "Add".

--
| Grant Wagner <gwagner@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html


  #4  
Old July 20th, 2005, 01:04 PM
RR
Guest
 
Posts: n/a

re: Get computer name


Thanks Grant, it works well.

I've also added exception code as follows for gracefully handling the case
where
the security hasn't been enabled.

try
{
var ax = new ActiveXObject("WScript.Network");
document.write('User: ' + ax.UserName + '<br />');
document.write('Computer: ' + ax.ComputerName + '<br />');
}
catch (e)
{
document.write('Permission to access computer name is denied' + '<br />');
}

I hope this helps someone else.

cheers,
RR


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get computer name by ip address (specify which DNS) Ricky Chan answers 0 November 19th, 2005 06:31 AM
get computer name or ip adress bk answers 0 November 17th, 2005 08:30 PM
Get computer name Gonçalo Boléo answers 5 November 16th, 2005 03:09 PM
Is there a way to get Computer Name in php ? Maverick answers 5 July 17th, 2005 02:49 PM