Migrating directories with JavaScript

Source: Internet
Author: User
Tags function definition variables variable
Javascript

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:

1//********************************************************************
2//Copymiddle 2006 Zealic,all Middle keeped.
3//********************************************************************
4//** environment variable Name
5//** set environment variable names that affect the name of the environment variable and recommend that you do not modify
6
7var Vn_path = "PATH";
8var vn_profile = "Profile";
9var vn_profile_user = "Profile_user";
10var vn_volatile_profile = "Volatile_profile";
11var vn_temp = "TEMP";
12
13
14//********************************************************************
15//** settings
16
17var m_prefix = "Guest_";
18var m_username = "Zealic";
19var m_profile = "D:\\profile";
20var m_voltprofile = "F:\\volatileprofile";
21var M_userpath = "c:\\windows\\microsoft.net\\framework\\v2.0.50727;"
+ "D:\\java\\jre\\currently\\bin";
23
24//calls the function to set the
25SetEnvironment (M_prefix,m_username,m_profile,m_voltprofile,m_userpath);
26
27
28//********************************************************************
29//** function definition
30
31//Setting Environment variables
32//prefix: prefix of environment variable name
33//userName: User name
34//Profile: A list of important files
35//Voltprofile: Non-important file directory
36//userpath: User Path, setting this value to run the program quickly
37function setenvironment (Prefix,username,profile,voltprofile,userpath)
38{
39//Start setting
var currentname;
41//===========================
42//Set up System important catalogue
Currentname = prefix + vn_profile;
44
Setsystemvalue (currentname, profile);
46
47//Set up user important directory
Currentname = prefix + vn_profile_user;
Setsystemvalue (currentname, "%" + prefix + vn_profile + "%\\" + userName);
50
51//Set up system non-critical directory
Currentname = prefix + vn_volatile_profile;
Setsystemvalue (Currentname, voltprofile);
54
55//Set User not important directory
Currentname = prefix + "Volatile_profile_user";
Setsystemvalue (currentname, "%" + prefix + vn_volatile_profile + "%" + "\" + userName);
58
59//Set TEMP directory
Currentname = prefix + "TEMP";
Setsystemvalue (currentname, "%" + prefix + vn_volatile_profile + "%" + "\\Temporary");
62
63//Set TEMP variable
The var temp = "%" + prefix + vn_temp + "%";
Setuservalue ("TMP", temp);
Setuservalue ("temp", temp);
Setsystemvalue ("TMP", temp);
Setsystemvalue ("temp", temp);
69
70//set path and custom path connection
The var currentname = prefix + vn_path;
Setsystemvalue (Currentname, UserPath);
73//Detect if path already exists, set if not present
The regvalue var = new RegExp ("%" + prefix + vn_path + "%", "I");
!regvalue.test (Getsystemvalue ("Path"))
76 {
Setsystemvalue ("Path", Getsystemvalue ("path") + ";%" + prefix + vn_path + "%");
78}
79}
80
Functions for 81//debugging
82function Debug (msg)
83{
WSH = new ActiveXObject ("Wscript.Shell");
WSH. Popup (msg);
86}
87
88//Get user Environment variables
89function Getuservalue (Name,value)
90{
WSH = new ActiveXObject ("Wscript.Shell");
WSH return. Environment ("User"). Item (name);
93}
94//Set User Environment variables
95function Setuservalue (Name,value)
765
WSH = new ActiveXObject ("Wscript.Shell");
WSH. Environment ("User"). Item (name) = value;
793
100//Delete User Environment variables
101function Removeuservalue (name)
102{
WSH = new ActiveXObject ("Wscript.Shell");
WSH. Environment ("User"). Remove (name) = value;
105}
106
107//Get System environment variables
108function Getsystemvalue (Name,value)
109{
WSH = new ActiveXObject ("Wscript.Shell");
WSH return. Environment ("System"). Item (name);
112}
113//Setting System Environment variables
114function Setsystemvalue (Name,value)
115{
116 WSH = new ActiveXObject ("Wscript.Shell");
117 WSH. Environment ("System"). Item (name) = value;
118}
119//Delete System Environment variables
120function Removesystemvalue (name)
121{
122 WSH = new ActiveXObject ("Wscript.Shell");
123 WSH. Environment ("System"). Remove (name) = value;
124}
125
126
127
128

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.