Sam
Sam

Reputation: 463

API to get hostname from Jscript

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

Upvotes: 1

Views: 1158

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1073968

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.

Upvotes: 5

Related Questions