用 JavaScript 迁移目录
这两天用虚拟机安装系统,准备用虚拟机把开发环境和数据库分离,想法如下: 但是装系统,还要设置环境变量,以减少系统盘的占用和增加性能,这就需要迁移系统盘的一些目录了,比如ie临时目录,临时文件夹,applocation data;此外,我们还需要把重要的文件夹移动到其他分区,以避免在系统盘发生事故或者想要恢复的时候,重要数据(mydocument,收藏夹,程序配置等)不受影响。 1//********************************************************************
1.开发环境为host
2.guest 为数据库服务器,每一个服务器都是一个独立的虚拟机
数据库包括,oracle 9i、sql server 2005、mysql
手动修改环境变量和注册表值太麻烦了,因为我每次装系统都要修改那么一次,这次实在受够了,心里一发狠。好,我写个脚本把你搞定!
bat是不能设置系统环境变量的,此外可用的就有 vbscript 和 jscript 了;vbscript 的好处是有对话框,jscript没有(alert等只能在网页中使用),而jscript 的代码条理清晰一些,并且功能强大,可以使用正则表达式等功能。
于是乎,写了下面的脚本,各位大虾请看代码:
2// copymiddle 2006 zealic,all middle keeped.
3//********************************************************************
4//** 环境变量名
5//** 设置环境变量名,这些值影响环境变量的名字,建议不要修改
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//** 设置
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;"
22 + "d:\java\jre\currently\bin";
23
24//调用函数以设置
25setenvironment(m_prefix,m_username,m_profile,m_voltprofile,m_userpath);
26
27
28//********************************************************************
29//** 函数定义
30
31// 设置环境变量
32// prefix : 环境变量名的前缀
33// username : 用户名
34// profile : 重要文件目录
35// voltprofile : 非重要文件目录
36// userpath : 用户 path,设置该值以进行快捷运行程序
37function setenvironment(prefix,username,profile,voltprofile,userpath)
38{
39 //开始设置
40 var currentname;
41 //===========================
42 // 设置系统重要目录
43 currentname = prefix + vn_profile;
44
45 setsystemvalue(currentname, profile);
46
47 // 设置设置用户重要目录
48 currentname = prefix + vn_profile_user;
49 setsystemvalue(currentname, "%" + prefix + vn_profile + "%\" + username);
50
51 // 设置设置系统非重要目录
52 currentname = prefix + vn_volatile_profile;
53 setsystemvalue(currentname, voltprofile);
54
55 // 设置设置用户非重要目录
56 currentname = prefix + "volatile_profile_user";
57 setsystemvalue(currentname, "%" + prefix + vn_volatile_profile + "%" + "\" + username);
58
59 // 设置临时目录
60 currentname = prefix + "temp";
61 setsystemvalue(currentname, "%" + prefix + vn_volatile_profile + "%" + "\temporary");
62