Installing ClickOnce application as non–admin user
Insight shipped a while ago. It is deployed as a ClickOnce application. The bootstrap setup.exe created by the .NET SDK is excellent in that it detects missing pre-requisites on a user’s machine, downloads and installs them.
The problem is that a non-admin user will not be able to install components such as the .NET Framework, Microsoft Reporting Library, etc.
“Right-click, RunAs admin” on the setup.exe works except that the Start Menu entry for the application is put in the Administrator’s start menu and home directory. This means the user has to run Setup.exe again as themself! Argh, imagine the support calls on that one…
My solution is to make a ZIP file containing setup.exe, Install.bat and part2.bat.
@echo off set _User_=%USERDOMAIN%%USERNAME% set _wd_=%CD% echo Installing Insight for %_User_%. runas /u:%COMPUTERNAME%\Administrator "cmd.exe /c CD \"%_wd_%\" && part2.bat \"%_User_%\" \"%_wd_%\""
which upon running prompts:
Installing Insight for WORK\Andrew Davey. Enter the password for WORK\Administrator:
The user types the admin password, hits enter. That runs part2.bat:
@echo off echo Giving %1 temporary Administrator status net localgroup Administrators %1 /ADD echo Running Insight install program runas /u:%1 "cmd.exe /c CD %CD% && setup.exe" echo Removing %1's Administrator status net localgroup Administrators %1 /DELETE
That adds the user to the Administrator group, then runs setup.exe as the user (but now with admin permissions). Afterwards, the user is removed from the Administrator group.
I took the idea from the MakeMeAdmin.cmd batch file. I could not seem to pass the current directory using MakeMeAdmin, so it could not find setup.exe. That’s why I have two batch files.
Maybe someone can point out how it should be done.
So the result is I can tell someone to download the ZIP, extract and double-click Install.bat. Whilst that’s not exactly “ClickOnce” anymore, it slightly better than the alternative! Of course once installed, any later application updates go into the user’s directory so no admin permissions are required.
I hope Microsoft update the bootstrapper in the next version so that it can handle non-admin users better.