Common application data path in Windows Installer

When I searched, there is a folder in the Windows section called "ProgramData" that contains application data that applications use at runtime. Since administrator permissions are not required for this folder, and this is a common rule for system users, this is the best place to place runtime files. In C # .Net, I get the address of this folder by this code:

Application.CommonAppDataPath 

The problem is that I cannot find the right folder to host my data while I create the Windows installer (msi file) using the Visual Studio installation project. I want to know how to add this folder to my installation project.

Sincerely.

+4
source share
2 answers

Here is how you can add it:

  • Go to the File System view in your project and right-click the File System on the Target Machine.
  • In the "Add a special folder" section, select "Custom folder" and specify a name
  • Now right-click on this folder and select "Properties Window"
  • Set the attribute "DefaultLocation" to the following: "[CommonAppDataFolder]"
  • Now you can add any subfolders that you want in this new folder, and put the necessary files there and your files should be installed in the desired path.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa367992(v=vs.85).aspx

+5
source

I found out that my question was wrong for my purpose due to permission material. The solution I found is written here at stackoverflow.com, and I mixed it up with the following code in my application to get the address of public documents.

 private static string getAddress() { RegistryKey rk = Registry.LocalMachine; RegistryKey sk = rk.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\explorer\\Shell Folders"); string address = ""; if (sk != null) { address = (string)sk.GetValue("Common Documents", @"c:\Users\Public\Documents"); } return address; } 

Let's look at what I said and what I did. At first I found out that what I want is wrong, and the ApplicationData folder is accessible only to this creator, while I need a folder that is used by all users. So I found the link and followed it, creating the folder that I wanted in FileSystem Explorer in my installer project. Then I changed my code to C # and made it read the address from the registry.

+1
source

Source: https://habr.com/ru/post/1436559/


All Articles