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
your code not working
What part isn’t working ? Any errors ?
It is displaying Host name rather Computer Name
Most often, they are the same.
Trying the code:
var network = new ActiveXObject(wscript.network);
returns the response:
‘wscript’ is undefined
Please disregard my previous comment. Fixed the issue. Needed an IE security setting changed.
Hi,
How can we get the computer name or host name in browsers other than IE
I don’t think you’d be able to. This relied on ActiveX which is not secure at all.
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?
You probably need to set the security permissions to the lowest possible.
this is not a solution, don’t work in macOS.
It’s a Windows-only function as it requires ActiveX…it’s also quite old and you’re better off using more modern technologies to do this.