May 182011
 

Hi all,

Thought I’d do a post on some JS as I haven’t done much in a while.
Today, I will go over some windows script host objects that may come in useful.
First up – wsh.network

Firstly we need to create the ActiveX Object in Javascript like so :


var wsh = new ActiveXObject(wscript.network)

Once this ActiveX Object is created, we can now use it to grab data from the computer using the properties of wsh.


var strCompName = wsh.computername;

That code snippet will store the NetBios computer name into strCompName, easy as pie.

If you have any questions or comments, please feel free to leave a comment below.

Reference
MSDN WSH.Neworking

Share

  10 Responses to “Javascript : Get the computer name with Javascript.”

  1. your code not working

  2. It is displaying Host name rather Computer Name

  3. Trying the code:

    var network = new ActiveXObject(wscript.network);

    returns the response:

    ‘wscript’ is undefined

  4. Please disregard my previous comment. Fixed the issue. Needed an IE security setting changed.

  5. Hi,
    How can we get the computer name or host name in browsers other than IE

  6. I think we need to add some settings into IE browser then only it will work otherwise it won’t work.
    so, could please let me know what settings we need to add into IE?

Leave a Reply to Bill Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)