installshield中的Path设置

meetwinter 2003-08-20 04:39:18
在用installshield制作安装程序的时候,我想在目的计算机上的path搜索路径中加上执行文件的路径,如:TARGET ^ "bin";%PATH%

我采用的方法是首先RegDBGetKeyValueEx()函数得到原始的Path值,然后将此值与TARGET ^ "bin"相拼接,最后再用RegDBSetKeyValueEx()写入。
现在的问题是当我卸载程序的时候,整个Path都被删除掉了,这当然不是我所期望的,不知有什么好的办法可以避免,或者说是否有一种更巧妙的方法实现我的目的。
...全文
220 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
meetwinter 2003-08-28
  • 打赏
  • 举报
回复
问题已解决。遇到同样情况的各位同行可参照以下代码:
function AddPath(szDir)
STRING svShortDir;
STRING szNewPath;
STRING szOldPath;
NUMBER nvResult;
NUMBER nvAlreadyThere;
STRING svResult;
begin

Disable(LOGGING);

svShortDir=szDir;
LongPathToShortPath ( svShortDir );

nvAlreadyThere = FALSE;
if (GetEnvVar("PATH",szOldPath)=0) then
nvAlreadyThere = szOldPath % svShortDir;
endif;

if (!nvAlreadyThere) then

GetSystemInfo ( OS , nvResult , svResult );

// us a different routine if we are in Windows NT
if (nvResult = IS_WINDOWSNT) then
nvResult = AddNTPath(svShortDir);
else
svShortDir = "%PATH%;" + svShortDir;
nvResult = EzBatchAddPath ( "PATH" , svShortDir , "" , AFTER );
endif;

endif;

Enable(LOGGING);

return nvResult;

end;

// SIAS
// ----
// There are also problems with InstallShield's environment variable handling
// this set of routines handles them better
//
// First - make an environment variable - general routine
function MakeEV(szVar,szValue)
NUMBER nvResult;
STRING svResult;
STRING svFileName;
begin

GetSystemInfo ( OS , nvResult , svResult );
// use a different routine for NT
if (nvResult = IS_WINDOWSNT) then
return MakeNTEV(szVar,szValue);
else
BatchGetFileName ( svFileName );
//ZapBatchLine (svFileName, "SET " + szVar );
EzBatchAddString((szVar + "=" + szValue),"",REPLACE);
return EzBatchReplace ( "SET " + szVar + "=" + szValue );
endif;

end;

// Same routine as "MakeEV" above but specifically for NT
function MakeNTEV(szVar,szValue)
NUMBER nResult;
POINTER pEnv;
STRING szKey,szEnv;
begin

szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult = RegDBSetKeyValueEx(szKey, szVar, REGDB_STRING, szValue, -1);
if (nResult >= 0) then
// Flush the NT registry to all applications.
szEnv = "Environment";
pEnv = &szEnv;
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, pEnv );
endif;

return nResult;

end;

// Ass to the NT PATH Environment variable
function AddNTPath(szDir)
NUMBER nResult;
POINTER pEnv;
STRING szKey,szEnv;
STRING szOldPath,szNewPath;
NUMBER nvLen,nvType;
begin


szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult = RegDBGetKeyValueEx(szKey, "Path", nvType, szOldPath, nvLen);
if (nResult >= 0) then
szNewPath=szOldPath + ";" + szDir;
nResult = RegDBSetKeyValueEx(szKey,"Path", REGDB_STRING, szNewPath, -1);
if (nResult >= 0) then
// Flush the NT registry to all applications.
szEnv = "Environment";
pEnv = &szEnv;
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, pEnv );
endif;
endif;
return nResult;

end;
踏岸寻柳 2003-08-28
  • 打赏
  • 举报
回复
2000以后的都是在系统环境变量中设置path,原来的autoexec.bat已经没有作用了???

是这样的吗!?我不是很清楚!

其实在InstallShield里面有这样的函数:BatchAdd,顾名思义,就是在OS的Autoexec.bat文件中添加信息的,不仅仅局限于路径信息 :)

在IS 6.22的帮助文件中是这么说的:
For example, if you want to add the environment variable TEMP to the Autoexec.bat file, you would want to add a statement like this:
SET TEMP=C:\Windows\Temp
To add the TEMP variable after the PATH statement:
SET PATH=C:\Win32s
Use this code in your setup script:
BatchAdd("TEMP", "C:\\Windows\\Temp", "PATH", AFTER);
When you set an environment variable, do not end the statement with a semicolon.
The BatchAdd function automatically adds the word "SET" before the environment variable and the equal sign (=) after the environment variable. The BatchAdd function does not add anything if szKey is a command statement (specified with the COMMAND option).
When you are finished making the changes to the Autoexec.bat file, call the BatchFileSave function to save the changes to disk. When you save the file, you can also create a backup file.

但是,它并没有涉及到如何卸载一部分配置信息的问题,再考虑考虑。
sljz 2003-08-20
  • 打赏
  • 举报
回复
因为2000以后的都是在系统环境变量中设置path,原来的autoexec.bat已经没有作用了,是不是可以这样:
path在autoexec.bat中添加
OpenFileMode(FILE_MODE_APPEND);
OpenFile(nvFileHandle,"C:\\","Autoexec.bat");
WriteLine(nvFileHandle,"SETPATH=%PATH%;C:\\bin");

然后反安装的时候将这行删除。。。

我没有测试过,不知道说的对不对,请批评指正。
lqbn 2003-08-20
  • 打赏
  • 举报
回复
您的思想其实是正确的,我也是这样想的。

其实在OnFirstUIAfter函数中加入安装时的注册表操作;然后相应的在OnMoving函数中加上卸载时的注册表操作即可。

4,164

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 一般软件使用
社区管理员
  • 一般软件使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧