User creation and service install: managing user during install, update and unistall - Advanced Installer Community
scambias
Posts: 29
Joined: Tue Nov 19, 2019 3:26 pm

User creation and service install: managing user during install, update and unistall

Hello,

I have built a setup that installs a service and creates a new user to run it. It works apparently fine but I would like to manage these conditions in a smart way:
1. when installing a new version (still running the setup), I expect the user and the service are there so I would like to just stop the service (and not unistall it) and leave that user (not removing it and create it again).
2. when uninstalling for good (i.e. from control panel), I need to remove everything.
How can I distinguish those two apparently similar "unistall" conditions?

In the Upgrades page I can set "uninstall old version first and then install new version": does this automatically do what I expect on point 1?

Thanks a lot in advance,
Silvio
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: User creation and service install: managing user during install, update and unistall

Hello Silvio,

Basically, an upgrade process means the uninstall of the older version and the install of the newer version.

With that being said:
1. when installing a new version (still running the setup), I expect the user and the service are there so I would like to just stop the service (and not unistall it) and leave that user (not removing it and create it again).
This means that we should not delete the service during an uninstall. To do so, you can go to "Services" page --> control operations --> uncheck the "Delete" option from the "On uninstall" action, leaving only the "Stop" option checked.

Additionally, you should also make the executable of your service permanent, so the setup does not delete it. For more information about this, please have a look over the "How do I prevent a file or registry entry from being uninstalled or repaired?" article which I think you may find useful.

However, please keep in mind that by doing this, this basically means that your service should never change (e.g. its functionality will always stay the same).

The deletion of the user created by the install also happens during the uninstall of the older version. To stop that from happening, you should condition the execution of the action that deletes the user. However, please keep in mind that this should be done in the older package. To do so, you can go to "Table Editor" page --> "InstallExecuteSequence" table --> "AI_UninstallAccounts" action add the following condition to that:

Code: Select all

NOT UPGRADINGPRODUCTCODE
The UPGRADINGPRODUCTCODE is a property which is set in the package that is being uninstalled by an upgrade (your older package).

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
scambias
Posts: 29
Joined: Tue Nov 19, 2019 3:26 pm

Re: User creation and service install: managing user during install, update and unistall

Hello Catalin,

thanks a lot for your reply. I still have a couple of problems.

I think I need to tell you what my setup does: it basically installs a service and creates (if needed) a user to run it.
The steps, roughly, are:
0. at start, it checks whether the service already exists, and if so, it gets the username from the registry aided key (with a search registry task plus a custom script action): this will make the behavior look like the user cannot be chosen (on step 1 the textfield will be readonly)
1. it asks, with a dialog containing a textfield (pre-populated with a suggested name but the user may change it), for a username to be used by the service: if it exists, the next dialog will ask for his password (and then performs the password valid check). If it does not exist, then the next dialog will ask to choose a password (with typical two textfields to repeat it twice). This dialog "next" button will perform some checks (password valid, password not empty, and so on)
2. on the User/Group page I created a user (as its name I used the property wrapped by square brackets) as password using the property set on step 1, flagging skip user creation if the user already exists
3. on the execution steps I run some scripts to give to the user the priviledges (even if I recently discovered that this can be done in the service configure section (I put SeTcbPrivilege[~]SeSecurityPrivilege[~]SeTakeOwnershipPrivilege[~]SeBackupPrivilege[~]SeRestorePrivilege as settings for list of priviledges required by the service).

Having said that, on first installation I do succeed in the case the user is created by the setup but do not when the user is already existing (the service has problems to start, asking for retry -> if I go on the windows services listing and change the logon details of the just created service, then hitting retry it starts fine)

On the upgrade, I get the same error because according to the algorithm I wrote before, it appears as the user already existing and therefore still the service is there but not enough privileges to start.

Finally, one note: the setup/upgrade can actually change the executable of the service so I would like the files to be deleted (even if the service is not) for them to be replaced by the upgrade.

I hope I was clear: I know the topic is quite difficult without having setup aip file (which I can provide if necessary).

Thank you very much,
Silvio
scambias
Posts: 29
Joined: Tue Nov 19, 2019 3:26 pm

Re: User creation and service install: managing user during install, update and unistall

Hi Catalin,

I got it working. There were some usage techniques which I happened to find as wrong.
For example: in the dialog phase I stored some values on properties (declared and set with a default value in the property list) which during the execution phase were again set to the default. I don't understand why this happens (I am not that expert on Adv Inst) but I changed the algorithm differently avoiding using personal properties that must be used at execution time on some custom action scripts.
Thanks again,
Silvio
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: User creation and service install: managing user during install, update and unistall

Hello Silvio,

Thank you for your followup on this.

I am glad everything works as expected now.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”