Get computer name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RR

    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.Applicati on");

    then I thought to run
    oShell.ShellExe cute 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


  • RR

    #2
    Re: Get computer name

    BTW, I want this to run in Internet Explorer.

    thanks,
    RR


    Comment

    • Grant Wagner

      #3
      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.Applicati on");
      >
      > then I thought to run
      > oShell.ShellExe cute 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@agrico reunited.com>

      * Client-side Javascript and Netscape 4 DOM Reference available at:
      *


      * Internet Explorer DOM Reference available at:
      *
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


      * 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


      Comment

      • RR

        #4
        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


        Comment

        Working...