cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Adrien
Pilgrim

Last path demiliter in environment strings

Hi,

I need to add a path without last path delimiter in environment strings. According to the log, the property I write in the Environment table is correctly formatted (without last path delimiter), but value written by WriteEnvironmentStrings has the path delimiter:

WriteEnvironmentStrings: Name: MyEnvString, Value: C:\Test\, Action 536870913
...
Property(S): MyProperty = C:\Test


The Environment table:

[CODE]Environment Name Value Component_
NewEnvironment1 *=-MyEnvString [MyProperty] MyComponent[/CODE]

So, after installation, it's impossible to use paths like %MyEnvString%\SubDirectory (user need to search for %MyEnvString%SubDirectory, that is not usual).

Is there a way to do that ?

Thanks for help,
Adrien
Labels (1)
0 Kudos
1 Reply
Highlighted
Adrien
Pilgrim

Re: Last path demiliter in environment strings

Hi,

I have solved the problem by building the Environment table in a custom action. So I can directly add the path without delimiter, instead of using a formatted property in the Value field of the Environment table (which seems to automatically add a delimiter...).

in my case (custom action based on a Delphi dll function) it looks like this:

[CODE]procedure InitEnvironmentTable(hInstall: MSIHandle);
var
Db, View: MSIHandle;
Path, Query: string;
begin
if bsMsiGetProperty(hInstall, 'MYPATH', Path, MAX_PATH) then
begin
Path := ExcludeTrailingPathDelimiter(Path);
MsiLogStringFmt(hInstall, 'Adding MYPATH to Environment table... (%s)', [Path]);
Db := MsiGetActiveDatabase(hInstall);
if Db <> 0 then
try
Query := 'INSERT INTO `Environment` (`Environment`, `Name`, `Value`, `Component_`) ' +
'VALUES (''NewEnvString'', ''*=-MyEnvString'', ''' + Path + ''', ''MyComponent'') TEMPORARY';
try
if MsiDatabaseOpenView(Db, PAnsiChar(Query), View) <> ERROR_SUCCESS then
MsiLogString(hInstall, MsiGetLastErrorRecord)
else if MsiViewExecute(View, 0) <> ERROR_SUCCESS then
MsiLogString(hInstall, MsiGetLastErrorRecord)
else
MsiLogString(hInstall, 'MYPATH added to Environment table.');
finally
MsiCloseHandle(View);
end;
finally
MsiCloseHandle(Db);
end;
end;
end;[/CODE]

Hope this help !
Adrien
0 Kudos