1

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

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

5 Comments

This is pretty much I wanted. Keeping rocking! /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: 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! ;-)
What a nightmare ActiveX was 🙈
@MatthieuRiegler - Big time. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.