Migrating directory _javascript techniques with JavaScript

Source: Internet
Author: User
Tags function definition
These two days with virtual machine installation system, ready to use virtual machine to separate development environment and database, the idea is as follows:
1. Development environment for host
2.Guest is a database server, each server is a stand-alone virtual machine
Database includes Oracle 9i, SQL Server 2005, MySQL
But install the system, but also set the environment variables to reduce the system disk occupancy and increase performance, which requires the migration of some directories of the system disk, such as IE temporary directory, temporary folder, Applocation Data; In addition, we also need to move important folders to other partitions, To avoid critical data (MyDocument, Favorites, program configuration, etc.) that are not affected when the system disk crashes or wants to recover.
Manually modifying environment variables and registry values too troublesome, because every time I install the system to be modified so once, this time is enough, in the heart a ruthless. Okay, I'll write a script to get you out!
BAT is not allowed to set system environment variables, and in addition, VBScript and JScript are available; The advantage of VBScript is that there is a dialog box, JScript is not (alert, etc. can only be used in a Web page), and JScript's code is clear and powerful, and you can use features such as regular expressions.
So, write the following script, everybody prawns please look at the code:

Copy Code code as follows:
//********************************************************************
Copymiddle 2006 Zealic,all Middle keeped.
//********************************************************************
* * Environment variable name
* * Set environment variable names that affect the name of the environment variable and recommend that you do not modify
var Vn_path = "PATH";
var vn_profile = "Profile";
var vn_profile_user = "Profile_user";
var vn_volatile_profile = "Volatile_profile";
var vn_temp = "TEMP";


//********************************************************************
* * Settings

var m_prefix = "Guest_";
var m_username = "Zealic";
var m_profile = "D:\\profile";
var m_voltprofile = "F:\\volatileprofile";
var m_userpath = "c:\\windows\\microsoft.net\\framework\\v2.0.50727;"
+ "D:\\java\\jre\\currently\\bin";

Call the function to set the
Setenvironment (M_prefix,m_username,m_profile,m_voltprofile,m_userpath);


//********************************************************************
* * Function definition

Setting environment variables
Prefix: prefix of environment variable name
UserName: User Name
Profile: List of important files
Voltprofile: Non-important file directory
UserPath: User Path, setting this value to run the program quickly
function Setenvironment (Prefix,username,profile,voltprofile,userpath)
{
Start setting
var currentname;
//===========================
Set up system critical directories
Currentname = prefix + vn_profile;

Setsystemvalue (currentname, profile);

Setting up user-critical directories
Currentname = prefix + vn_profile_user;
Setsystemvalue (currentname, "%" + prefix + vn_profile + "%\\" + userName);

Set up system non-critical directory
Currentname = prefix + vn_volatile_profile;
Setsystemvalue (Currentname, voltprofile);

Setting up a user-critical directory
Currentname = prefix + "Volatile_profile_user";
Setsystemvalue (currentname, "%" + prefix + vn_volatile_profile + "%" + "\" + userName);

Set up a temporary directory
Currentname = prefix + "TEMP";
Setsystemvalue (currentname, "%" + prefix + vn_volatile_profile + "%" + "\\Temporary");

Set TEMP variable
var temp = "%" + prefix + vn_temp + "%";
Setuservalue ("TMP", temp);
Setuservalue ("temp", temp);
Setsystemvalue ("TMP", temp);
Setsystemvalue ("temp", temp);

Set path and customize path connection
var currentname = prefix + vn_path;
Setsystemvalue (Currentname, UserPath);
Detects if path already exists, setting if it does not exist
var regvalue = new RegExp ("%" + prefix + vn_path + "%", "I");
if (!regvalue.test (Getsystemvalue ("Path"))
{
Setsystemvalue ("Path", Getsystemvalue ("path") + ";%" + prefix + vn_path + "%");
}
}

Functions for debugging
function Debug (msg)
{
WSH = new ActiveXObject ("Wscript.Shell");
Wsh. Popup (msg);
}

Get User Environment variables
function Getuservalue (name,value)
{
WSH = new ActiveXObject ("Wscript.Shell");
return WSH. Environment ("User"). Item (name);
}
Setting User Environment variables
function Setuservalue (name,value)
{
WSH = new ActiveXObject ("Wscript.Shell");
Wsh. Environment ("User"). Item (name) = value;
}
Delete User Environment variables
function Removeuservalue (name)
{
WSH = new ActiveXObject ("Wscript.Shell");
Wsh. Environment ("User"). Remove (name) = value;
}
Get System Environment variables
function Getsystemvalue (name,value)
{
WSH = new ActiveXObject ("Wscript.Shell");
return WSH. Environment ("System"). Item (name);
}
Setting System Environment variables
function Setsystemvalue (name,value)
{
WSH = new ActiveXObject ("Wscript.Shell");
Wsh. Environment ("System"). Item (name) = value;
}
deleting system environment variables
function Removesystemvalue (name)
{
WSH = new ActiveXObject ("Wscript.Shell");
Wsh. Environment ("System"). Remove (name) = value;
}

Which profile for valuable data and documents, Volatileprofile used but no value of data and documents. In this way, we can clearly know that profile to retain, volatileprofile can be often cleaned up.
I also need to migrate the Desktop,my document,favorites folder to the profile directory and then start installing the database.
But, today is too late, tomorrow again ~ ~ ~
Use the JScript operation registry tomorrow to migrate some directories of the system to the profile and Volatileprofile directories.
Http://www.cnblogs.com/zealic/archive/2006/11/07/552433.html
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.