Archive: Code to install an application in user mode(Limited privilege)


Code to install an application in user mode(Limited privilege)
I am having an installer that will install the application only in the admin mode. If i try to install in user mode(Limited privilege), then it is saying that "you are not having administrator privilege to install this". But i want to install the application in user mode. Can anyone please tell me how to code in NSIS to install the application in user mode.
Thanks in advance.


Use the UserInfo plugin in .onInit:

UserInfo::GetAccountType
Pop $1
${If} $1 == "Admin"
StrCpy $ACCESSLEVEL "Admin"
SetShellVarContext all
${Else}
StrCpy $ACCESSLEVEL "NotAdmin"
SetShellVarContext current
${EndIf}

And then in the rest of your script you can use that variable to determine what code should be executed.
Note: For userlevel installs, the default installpath should be $LOCALAPPDATA\YourPath.
Note: If you want the user to be able to choose a different direction, you'll need to check for sufficient access privileges in the selected directory. (see here: http://forums.winamp.com/showthread.php?t=317018 ).
Note: If you don't want to use that, you'll probably need to skip the DIRECTORY page and force $LOCALAPPDATA as install dir.
Note: By setting SetShellVarContext in the above If Else code, you can use WriteRegStr SHCTX "software\etc" for both admin and userlevel registry commands


My product is having third party tools like JRE , Flash player , .. etc.. which requires only admin mode to install these software's. The above code is not working while installing the third party tools.


I am having an installer that will install the application only in the admin mode. If i try to install in user mode(Limited privilege), then it is saying that "you are not having administrator privilege to install this".My application has third party tools(Supporting softwares) like JRE , Flashplayer , .. etc. But i want to install the application in user mode. Can anyone please tell me in detail how to code in NSIS to install the application in user mode .
Thanks in advance.


...
You can´t install these 3rd party apps in usermode. There is no way around. You need adminrights.


Thanks for the reply. I can install Microsoft Office in User mode(Limited privilege).It will ask Admin password.After entering the password, It will install in the user mode with admin privilege. My requirement is like this.


...
Ah ok... i know what you want. But if you need adminrights for the 3rd party apps anyway why don´t you install your app with adminrights too? Do your app really NEED a userlevel install? Beacuse it would be much easier that way.

For Win Vista/7 (with UAC on) add following line to your code:

RequestExecutionLevel admin

and to ensure that the user have adminrights use the code from MSG in the .onInit function and have a look to the notes he wrote.


http://nsis.sourceforge.net/Docs/Chapter4.html#4.8.1.32


Thank you all for your notes and references.

We have decided not to install our app in User mode (Limited Privilege) and will only install in Admin mode. Here the install of our s/w and the associated 3rd party tools goes off fine.

However, I am facing a new problem. Our customers SHOULD have the option of running the app in User mode (after installing in Admin mode).

If the app is installed in C:\Program Files, then it doesnt work in User mode (it works alright in Admin mode). I have noticed that if the app is installed in another path say D:\ then it works alright.

Question - Why does this happen ? How is it possible to overcome this problem ?

Thank You


In what way does it not work? Is your application trying to write to that folder?

Stu


Thanks for the reply.
Yes. we are writing text file (.txt files) in that path.


...
This is (and always was) a bad idea. But you´re not the only one who does this mistake.
Apps should store files they want to write into (like configfiles etc.) in %APPDATA% and NOT in %PROGRAMFILES%. That is not a new fact but in the past many programmers don´t care about. Most incompatibilities of older programs running under vista/7 are related to this design fault.

Program -> %PROGRAMFILES%
configfiles (files that need write access in usermode) -> %APPDATA%