I have a windows installer, which is creating a database as a part of the installation process. While installing the application CREATE DATABASE
process is failing because the windows installer using a wrong user. It is using NT AUTHORITY\SYSTEM
instead of using the login user. NT AUTHORITY\SYSTEM
user does not have permission to create a database.
Is there any way to force the installer to use the login user?
Using Windows 10 environment with VS 2017 and MS Visual Studio 2017 Installer Projects.
The short answer is that you can't do this in a Visual Studio setup that is an InstallAllUsers setup because the all VS installer generated custom actions run as the system account. Therefore you'd need to change the custom action settings in the MSI file with an editing tool such as Orca. You'd find the custom action in the CustomAction table in the MSI file, look at the Type values (it's probably a type 3074) and then turn off the msidbCustomActionTypeNoImpersonate bit so that it runs impersonated as the installing user.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa368069(v=vs.85).aspx
Note that running impersonated as the installing user has its own set of issues because it is NOT the same as running as the interactive user. The user profile is not loaded, so objects associated with the user (such as HKCU, user profile folders) are very unreliable.
Many people populate the databases with a separate programs the first time the application is launched so that it runs properly as the interactive user and can be developed and debugged as a standalone program. If the populate fails during the install you either give up the install and roll back, or you continue the install and end up with an empty database, for which you might need a program to populate it anyway.