0

I have a Windows Form project and created a Setup Wizard Project so I users can install it in Next Next Finish way.

This project uses Microsoft Access as database and I properly added the database file to SetupWizard and everything was ok.

HOWEVER, after reinstallations I notice windows was copying the database file from "Application Folder" to C:\users\myUser\AppData\Local\VirtualStore\Program Files (x86)\.

And just FYI, my connection string in app.config:

<connectionStrings>
    <add name="<ProjectName>.Properties.Settings.databaseConnectionString"
     connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database.mdb;Persist Security Info=True;Jet OLEDB:Database Password=MyPassword"
providerName="System.Data.OleDb" />
</connectionStrings>

If I just gather the .exe from ProjectOutput and the database.mdb in the same folder it works perfectly.

When I make the install it copies the database file to C:\users\myUser\AppData\Local\VirtualStore\Program Files (x86)\ folder and its a problem since I want the user to install it where he pleases and that the file stays only there. (It is a software requirement btw).

I've also tried installation to "current user" and "all users" and the behavior is the same.

  • 2
    You cannot write to Program Files during normal usage. – SLaks Apr 28 '14 at 19:48
  • Selected `answer` on this [post](http://stackoverflow.com/questions/13854698/how-to-install-visual-studio-2010-setup-project-with-ms-access-database-on-a-com) might be helpful. – Hassan Apr 28 '14 at 19:54
  • Thanks @SLaks !! Your answer is correct. I have to find a workaround now ^^ – Talles Santana Apr 29 '14 at 12:06

1 Answers1

0

You have discovered folder redirection on UAC systems, that's what happens when you write to restricted folders on some OS versions:

http://blogs.windows.com/windows/archive/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx

Your code needs an elevation manifest for it to ask the user to elevate to admin. This might help:

http://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware

and you need requestedexecutionlevel administrator.

If you want limited users to be able to use your app then redesign it so it does not write to things that require admin privilege. That's what folders like User's Application Data are for.

PhilDW
  • 20,260
  • 1
  • 18
  • 28