By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

Get computer name

P: n/a
RR
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
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
RR
BTW, I want this to run in Internet Explorer.

thanks,
RR
Jul 20 '05 #2

P: n/a
RR wrote:
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


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 <gw*****@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
Jul 20 '05 #3

P: n/a
RR
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
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.