I prepared the setup of my project. When I install the setup in my computer, I have to give read-write permission to my folder and access database manually each time. How can we solve this problem?
Loading
I prepared the setup of my project. When I install the setup in my computer, I have to give read-write permission to my folder and access database manually each time. How can we solve this problem?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajkiran SwainPosted Mar 29, 2023, 8:07 PM
One way to solve this problem is to include a custom action in your installation package that sets the appropriate permissions on the target folder and database.
Here are the steps you can follow:
In your setup project, right-click on "Custom Actions" and select "Add Custom Action".
In the "Select Item in Project" dialog, choose the "Application Folder" and select "Add Output" to add your application's primary output.
Right-click on the custom action you just added and select "Properties". In the properties window, set the "CustomActionData" property to the folder and database name that you want to set permissions for, for example: /folder="[TARGETDIR]MyFolder" /database="MyDatabase".
Add a custom action to set permissions on the folder by selecting "Add Custom Action" again and choosing "Application Folder". Then, select "Add File" and browse to the folder where your application is installed. Choose the file "icacls.exe" from the System32 folder and click "Open".
Right-click on the custom action you just added and select "Properties". In the properties window, set the "Arguments" property to something like: "[TARGETDIR]icacls.exe [TARGETDIR]MyFolder /grant Users:(OI)(CI)R". This command grants the "Users" group read/write permissions on the folder.
Repeat steps 4 and 5 to add a custom action to set permissions on the database. This time, choose "System Folder" instead of "Application Folder", and use the "sqlcmd.exe" file instead of "icacls.exe". The command you use to set permissions will depend on the type of database you are using, but it should be similar to the folder permissions command.
Build and test your setup package to make sure the custom actions are working as expected.
I hope this helps you solve the problem! Let me know if you have any further questions.
Mehmet FatihPosted Mar 30, 2023, 3:40 PM
Thanks a lot Rajkiran Swain.