步骤如下:
1、在Installation Designer中点击左栏的【Behavior and Logic】-【InstallScript】标签展开,然后在右边的【Files】上点右键,选择【New Script Files】,生成一个Setup.rul文件。在文件中添加如下语句:
export prototype myAddAPathNew(HWND);
function myAddAPathNew(hMSI)
STRING szPath;
NUMBER nRootKey, nvType, nvSize;
begin
nRootKey = HKEY_LOCAL_MACHINE;
if (RegDBSetDefaultRoot(nRootKey) = 0 )then
// 添加系统路径
RegDBGetKeyValueEx( " SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment " , " Path " ,nvType,szPath,nvSize);
if szPath != "" then
// MessageBox(szPath,INFORMATION);
PathSet(szPath);
PathDelete( " GPMT " ,PARTIAL);
PathAdd(CommonFilesFolder + " GPMT " , "" , PARTIAL, BEFORE);
PathGet(szPath);
// MessageBox(szPath,INFORMATION);
else
szPath = CommonFilesFolder + " GPMT " ;
endif;
RegDBSetKeyValueEx( " SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment " , " Path " ,REGDB_STRING,szPath, - 1 );
endif;
end;
2、在Installation Designer中点击左栏的【Behavior and Logic】-【Custom Actions and Sequences】标签展开,然后在右栏的【Custom Actions】上点击右键,选择【New InstallScript】,命名为【myTestAction】。然后使用向导,在【Action params】中选择在InstallScript中定义的函数,在此例中为myAddPathNew,其余采用默认设置即可。
3、在右栏的【Sequences】-【Installation】-【Execute】上面点击右键,选择【Insert】,选择【myTestAction】即可。
编译你的工程,当安装程序运行时,就可以为目标机器的路径中添加一个路径。