views:

50

answers:

1

Hi, I am not sure why my previous post was not listed. Lets see if this one gets listed. I have a stand alone jScript which passes parameters to a C# program. I have to pass hostname to the C# program. Is there an api which I can use to get hostname in the jScript if not can I do it using the 'hostname' system command?

Thanks in Advance. Sam

+3  A: 

Since you're using JScript I assume you're running under Windows. You can get the current computer's name from the environment:

var env, computerName;
env = new ActiveXObject("WScript.Shell").Environment("Process");
computerName = env("COMPUTERNAME");

...if that's what you mean by hostname. More on environments (there are more than one available, above I picked the process's environment) here.

T.J. Crowder
This is pretty much I wanted. Keeping rocking!/Sam
Sam
When I run multiple of these scrips. This is creating lots of WScript.exe*32 process on the system. Should I do delete env after getting ComputerName? Thanks in advance,Sam
Sam
@Sam: No, you can't delete a `var`. You may want to add `env = undefined;` after you're done using it, to explicitly break the reference to it. Blast Microsoft and their reference counting issues! ;-)
T.J. Crowder