Connecting Tech Pros Worldwide Help | Site Map

Get computer name

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 12:01 PM
RR
Guest
 
Posts: n/a
Default Get computer name

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, 12:01 PM
RR
Guest
 
Posts: n/a
Default Re: Get computer name

BTW, I want this to run in Internet Explorer.

thanks,
RR


  #3  
Old July 20th, 2005, 12:01 PM
Grant Wagner
Guest
 
Posts: n/a
Default 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, 12:04 PM
RR
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.