Set environment variables using js

//  Debug function
function show(msg)
{
wsh = new ActiveXObject("WScript.Shell");
wsh.Popup(msg);
}
// Perform
//eval
//try {
// Debug("dkjkljei");
//} catch (e) {
//}

/**
wsh = new ActiveXObject("WScript.Shell");
 Gets the user environment variables
wsh.Environment("user").Item(name);
 Set the user environment variables
wsh.Environment("user").Item(name) = value;
 Delete user environment variables
wsh.Environment("user").Remove(name);
 Gets the system environment variables
wsh.Environment("system").Item(name);
 Set the system environment variables
wsh.Environment("system").Item(name) = value;
*/
function addEnvVar(sys, obj, value) {
wsh = new ActiveXObject("WScript.Shell");
wsh.Environment(sys).Item(obj) = value;
}
function delEnvVar(obj) {
wsh = new ActiveXObject("WScript.Shell");
wsh.Environment("user").Remove(obj);
}
function getEnvVar(sys, obj) {
wsh = new ActiveXObject("WScript.Shell");
return(wsh.Environment(sys).Item(obj));
}
/**
Set ws=WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(ws.CurrentDirectory)
Set fc = f.Files
For Each f1 in fc
   if right(f1.name,len(f1.name)-InStrRev(f1.name,"."))="reg" then ws.run "regedit /s """&f1.name&""""
Next
*/
function showDir() {
var fso, f, fc, s;
wsh = new ActiveXObject("WScript.Shell");
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(wsh.CurrentDirectory);
fc = new Enumerator(f.files);
s = "";
var regValue = new RegExp(".java$","i");
for (; !fc.atEnd(); fc.moveNext()) {
  if (regValue.test(fc.item())) {
   var ff = fc.item();
   s += ff.Name;
   s += "\n";
  }
}
return(s);
}
var jdk = "d:\\java\\jdk";
function setJDK(obj) {
// Set  java_home
addEnvVar("system", "java_home", obj);
var path = getEnvVar("system", "path");
var pathbak = getEnvVar("system", "pathbak");
// Determine the existence of pathbak, not the Add
if (pathbak == "") {
  addEnvVar("system", "pathbak", path);
}
// Set  path
addEnvVar("system", "path", path + ";%java_home%\\bin");

var cp, fso, f, fc, ff;
wsh = new ActiveXObject("WScript.Shell");
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(obj + "\\lib");
fc = new Enumerator(f.files);
cp = ".;";
var regValue = new RegExp(".jar$","i");
for (; !fc.atEnd(); fc.moveNext()) {
  ff = fc.item();
  if (regValue.test(ff.name)) {
   cp += "%java_home%\\lib\\" + ff.name + ";";
  }
}
// Set  classpath
addEnvVar("system", "classpath", cp);
}
eval(run());
function run() {
wsh = new ActiveXObject("WScript.Shell");
wsh.run("regedit");
}

Set environment variables using js

分类:Web 时间:2010-06-05 人气:233
分享到:
blog comments powered by Disqus

相关文章

  • % System environment variables can not even refer to the user environment variables ..% 2010-11-09

    Previously did not know there is such a problem, because in the past not to use% java environment variables in the configuration when System variable path% JAVA_HOME% \ bin User variable JAVA_HOME D: \ Program Files \ Java .... The results can not be

  • Set jdk and tomcat with the batch environment variables 2008-10-27

    Studied Java programming should know, is to set the JDK environment variable, this is troublesome for. Here's what I wrote a batch used to set environment variables. We put the following code to copy down and save it as bat file is a batch file, and

  • (Transfer) Ubuntu environment variables 2010-02-13

    Environment variable configuration file In Ubuntu, there are several files you can set the environment variable 1, / etc / profile: In the log, the operating system to use when customizing the user environment, the first file, the file system setting

  • groovy grails set up environment variables 2010-07-14

    Premise: java environment variables set correctly. Download grails-1.3.3 Set environment variables: 1, GRAILS_HOME D: \ 2010 \ grails-1.3.3 2, path % GRAILS_HOME% \ bin / / Note that capital Run Enter: grails welcom you can see! Download groovy-1.5.0

  • java environment variables 2010-07-21

    1] in My Computer, right click and select [Properties] 2, select the System Properties] [top panel] [Advanced Options, then select the following environment variables] [ 3, in the bottom of the] [System Variables list, find the variable named "JAVA_H

  • linux modify the system environment variables need to reboot the machine 2010-07-27

    1 summarizes the background In linux system, if you download and install the application, is likely to type its name when "command not found" prompt content. If the target every time to the installation folder, locate the executable file to be t

  • Ubuntu environment variables 2010-08-19

    Environment variable configuration file In Ubuntu, there are several files you can set the environment variable 1, / etc / profile: In the log, the operating system to use when customizing the user environment, the first file, the file system setting

  • Ubuntu set the environment variables (2) 2010-08-19

    In the Ubuntu system, there are two ways to set the environment variable PATH. The first one applies for a single user to set PATH, the second is the global setting PATH. The first method: In the user home directory has a. Bashrc file, you can add th

  • linux set environment variables 2010-09-14

    linux set environment variables 1 Introduction In linux system, if you download and install the application, is likely to type its name when "command not found" prompt content. If the target every time to the installation folder, locate the exec

  • ubuntu description of environment variables 2010-10-10

    http://hi.baidu.com/kxw102/blog/item/c1759e3e4fe315cb7c1e711b.html Today they learned the environment variable settings, a number of relatively deep feelings, first of all I have to know from the Internet and share with you. Shell environment variabl

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.419 (s). 12 q(s)