Reputation: 7062
How can I create a file in the directory in which my application is installed?
I've tried the following, and it doesn't work. Basically I need to be able to create the file in C:\Program Files\MyAppName\ on Windows XP or C:\Program Files(x86)\MyAppName on Windows Vista and newer.
SaveStringToFile("{pf}\{#MyAppName}\Registration.txt", Serial, False);
Upvotes: 1
Views: 3719
Reputation: 6167
It's better to use the special constant {app}, in case the user chooses a different directory to install it in.
SaveStringToFile(ExpandConstant('{app}\Registration.txt'), Serial, False);
To save the file in the Application Data directory (shared by all users), use the constant {commonappdata}
instead of {app}
.
Note that {app}
points to "C:\Program Files\My Application\" (or wherever the user chose to install the application and depending on the OS). {commonappdata}
, on the other hand, points to the root of the Application Data directory, so it'd be good idea in this case to add a directory for your app, (or company and app):
For example:
SaveStringToFile(ExpandConstant('{commonappdata}\Foobar Corporation\Our Application\Registration.txt'), Serial, False);
Upvotes: 6
Reputation: 12119
Assuming this is a permissions issue you should use Environment.SpecialFolders.ApplicationData
instead. It has an added benefit of allowing you to keep your file if application is uninstalled which can be very useful...
Upvotes: -1