简体   繁体   中英

How to create a text file in the directory my application is installed with INNO SETUP?

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);

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);

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...

try this string path = Environment.CurrentDirectory;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM