Skip to content

Instantly share code, notes, and snippets.

@jayrgee
Created December 5, 2014 02:07
Show Gist options
  • Save jayrgee/b254315ce39bef7a425b to your computer and use it in GitHub Desktop.
Save jayrgee/b254315ce39bef7a425b to your computer and use it in GitHub Desktop.
Includes IE-specific ActiveXObject
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ActiveXObject</title>
</head>
<body>
<h1>ActiveXObject</h1>
<h2>Environment Variables</h2>
<h3>Computer Name</h3>
<ul>
<li>COMPUTERNAME: <span id="env-computername">?</span></li>
</ul>
<h3>All Variables</h3>
<ul id="allvars"></ul>
<script>
//(function () {
function getEnvironmentSettings() {
var wsh = null,
env = null;
try {
wsh = new ActiveXObject("Wscript.Shell");
} catch (ex) {
console.log(ex.name + ': ' + ex.message);
}
if (wsh !== null) {
try {
env = wsh.Environment("PROCESS");
} catch (ex) {
console.log(ex.name + ': ' + ex.message);
}
}
return env;
}
function getEnvironmentSetting(key) {
var env = getEnvironmentSettings(),
value = "";
if (env !== null) {
try {
value = env.Item(key);
} catch (ex) {
console.log(ex.name + ': ' + ex.message);
}
}
return value;
}
function listEnvironmentSettings(listId) {
var list = document.getElementById(listId),
listItem,
span;
var settings = getEnvironmentSettings();
var env = [];
var x, e;
if (settings !== null) {
e = new Enumerator(settings);
for (; !e.atEnd(); e.moveNext()) {
x = e.item().split("=");
env.push({"key": x[0], "value":x[1]});
listItem = document.createElement("li");
listItem.textContent = x[0] + ": ";
span = document.createElement("span");
span.textContent = x[1];
listItem.appendChild(span);
list.appendChild(listItem);
}
}
console.log(env);
}
var computerName = getEnvironmentSetting("COMPUTERNAME"),
allVars = getEnvironmentSettings();
console.log(computerName);
if (computerName.length > 0) {
var s = document.getElementById("env-computername");
s.textContent = computerName;
}
listEnvironmentSettings("allvars");
//} ());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment