使用Setup Factory修改Path变量的方法

在Setup Factory中脚本如下:

strPath = Registry.GetValue(HKEY_CURRENT_USER, "Environment", "path", true);

  if strPath ~= "" then

  strPath = String.Concat(strPath, ";");

  end

  strPathToAdd = SessionVar.Expand("%AppFolder%");

  strPathToAdd = String.Concat(strPathToAdd,"file://MATLAB6p5//bin//win32");

  -- 如果路径中无该位置,则加入

  if String.Find(strPath,strPathToAdd) == -1 then

  strPath = String.Concat(strPath, strPathToAdd);

  Registry.SetValue(HKEY_CURRENT_USER, "Environment", "path", strPath, REG_SZ);

  end

这个是修改用户环境变量的,如果想要修改系统环境变量,可以修改\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001

\Control\Session Manager\Environment\Path.

 

另附环境变量和注册表的对应关系:

环境变量分为两类:用户变量与系统变量,在注册表中都有对应的项。其中用户变量所在位置:

HKEY_CURRENT_USER\Environment;系统变量所在位置为:\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001

\Control\Session Manager\Environment。 

posted on 2010-06-03 17:59  zhanghw0354  阅读(4010)  评论(1编辑  收藏  举报