P E Schoen
2010-12-14 04:37:34 UTC
I have an application written in Delphi 4, originally on a Windows XP
platform. As it matured it needed an installation script which I developed
using Inno Setup, and for XP it used the proper "Program Files" and "Program
Data" folders. When I first installed it on Vista I had to deal with the
different location for data, which was solved by using the proper system
constants. But I found that any files that were created or changed by the
application were "virtualized" in a separate Program Data folder under the
user ID.
Now I am testing it on a Win7 platform, and the virtualization is similar.
It seemed innocuous enough because the required files were properly
installed in the Program Data folder, but when the program updated the
database files, they were virtualized and no longer where I had expected
them to be. And when I made changes to the database for new installations,
the program still used the unchanged files in the virtual folder.
The way I understand this is that the default user permissions, even for a
user with administrator privileges, are such that changing and writing to a
"protected" directory such as Program Data will automatically virtualize the
files. The administrator may change the user permissions for the directory,
and then the virtualization will not occur. However, if a file has already
been created in the virtual directory, that is what will be used unless it
is renamed or moved to the normal folder.
I'm trying to determine what is the best way to handle new installations
which may or may not be used on systems that have been used for a while in
the virtualized environment. I have found a utility called SetACL.exe, which
can programmatically change the permissions of the folder for the current
user. This seems to work well, but I'm trying to figure out the best way to
do this so it will work on XP, Vista, and Win7. Here is what I have for the
Inno setup script:
Filename: "{tmp}\SetACL.exe"; Parameters: "-on
{commonappdata}\Ortmaster -ot file
-actn ace -ace ""n:{username};p:change,write""
-log ""{commonappdata}\Ortmaster\setacl.log"" "
[code]
function MyProgCheck: Boolean;
var VirtualFileFolder: String;
var VirtualFileName: String;
var username: String;
begin
username := GetUserNameString();
VirtualFileFolder := 'C:\Users\'+ username+
'\AppData\Local\VirtualStore\ProgramData\Ortmaster\';
VirtualFilename := VirtualFileFolder +'Ortres.dbf';
If fileexists(VirtualFilename) then begin //1
if MsgBox('MyProg:' #13#13 'Do you want to rename virtual file '
+ VirtualFileName + '?', mbConfirmation, MB_YESNO)
= idYes then begin //2
if renamefile( VirtualFilename, VirtualFileFolder+'Ortres.dbk' )
then
result := True
else begin
MsgBox( 'File Rename Error', mbInformation, MB_OK );
result := False; end;
end //-2
else begin
MsgBox( 'File not found: ' + VirtualFileName, mbInformation,
MB_OK );
result := False;
end;
end;
end;
I will need to check for other files as well. This is not a final solution,
and I will probably move the file to the usual Program Data folder rather
than rename it. But then I will also need to make sure that no data is lost.
I have some ideas, but I was just hoping someone may have some experience
with this and offer some suggestions.
Thanks,
Paul
platform. As it matured it needed an installation script which I developed
using Inno Setup, and for XP it used the proper "Program Files" and "Program
Data" folders. When I first installed it on Vista I had to deal with the
different location for data, which was solved by using the proper system
constants. But I found that any files that were created or changed by the
application were "virtualized" in a separate Program Data folder under the
user ID.
Now I am testing it on a Win7 platform, and the virtualization is similar.
It seemed innocuous enough because the required files were properly
installed in the Program Data folder, but when the program updated the
database files, they were virtualized and no longer where I had expected
them to be. And when I made changes to the database for new installations,
the program still used the unchanged files in the virtual folder.
The way I understand this is that the default user permissions, even for a
user with administrator privileges, are such that changing and writing to a
"protected" directory such as Program Data will automatically virtualize the
files. The administrator may change the user permissions for the directory,
and then the virtualization will not occur. However, if a file has already
been created in the virtual directory, that is what will be used unless it
is renamed or moved to the normal folder.
I'm trying to determine what is the best way to handle new installations
which may or may not be used on systems that have been used for a while in
the virtualized environment. I have found a utility called SetACL.exe, which
can programmatically change the permissions of the folder for the current
user. This seems to work well, but I'm trying to figure out the best way to
do this so it will work on XP, Vista, and Win7. Here is what I have for the
Inno setup script:
Filename: "{tmp}\SetACL.exe"; Parameters: "-on
{commonappdata}\Ortmaster -ot file
-actn ace -ace ""n:{username};p:change,write""
-log ""{commonappdata}\Ortmaster\setacl.log"" "
[code]
function MyProgCheck: Boolean;
var VirtualFileFolder: String;
var VirtualFileName: String;
var username: String;
begin
username := GetUserNameString();
VirtualFileFolder := 'C:\Users\'+ username+
'\AppData\Local\VirtualStore\ProgramData\Ortmaster\';
VirtualFilename := VirtualFileFolder +'Ortres.dbf';
If fileexists(VirtualFilename) then begin //1
if MsgBox('MyProg:' #13#13 'Do you want to rename virtual file '
+ VirtualFileName + '?', mbConfirmation, MB_YESNO)
= idYes then begin //2
if renamefile( VirtualFilename, VirtualFileFolder+'Ortres.dbk' )
then
result := True
else begin
MsgBox( 'File Rename Error', mbInformation, MB_OK );
result := False; end;
end //-2
else begin
MsgBox( 'File not found: ' + VirtualFileName, mbInformation,
MB_OK );
result := False;
end;
end;
end;
I will need to check for other files as well. This is not a final solution,
and I will probably move the file to the usual Program Data folder rather
than rename it. But then I will also need to make sure that no data is lost.
I have some ideas, but I was just hoping someone may have some experience
with this and offer some suggestions.
Thanks,
Paul