Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 27th April 2011, 04:11   #1
balamdu01
Junior Member
 
Join Date: Apr 2011
Posts: 7
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.
balamdu01 is offline   Reply With Quote
Old 27th April 2011, 05:15   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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
MSG is offline   Reply With Quote
Old 27th April 2011, 13:53   #3
balamdu01
Junior Member
 
Join Date: Apr 2011
Posts: 7
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.
balamdu01 is offline   Reply With Quote
Old 27th April 2011, 13:56   #4
balamdu01
Junior Member
 
Join Date: Apr 2011
Posts: 7
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.
balamdu01 is offline   Reply With Quote
Old 27th April 2011, 14:04   #5
Highcoder
Member
 
Join Date: Jan 2011
Posts: 69
...

You can´t install these 3rd party apps in usermode. There is no way around. You need adminrights.
Highcoder is offline   Reply With Quote
Old 27th April 2011, 14:40   #6
balamdu01
Junior Member
 
Join Date: Apr 2011
Posts: 7
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.
balamdu01 is offline   Reply With Quote
Old 27th April 2011, 14:58   #7
Highcoder
Member
 
Join Date: Jan 2011
Posts: 69
...

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.
Highcoder is offline   Reply With Quote
Old 27th April 2011, 14:58   #8
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
http://nsis.sourceforge.net/Docs/Chapter4.html#4.8.1.32
jpderuiter is offline   Reply With Quote
Old 2nd May 2011, 10:30   #9
balamdu01
Junior Member
 
Join Date: Apr 2011
Posts: 7
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
balamdu01 is offline   Reply With Quote
Old 2nd May 2011, 10:40   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
In what way does it not work? Is your application trying to write to that folder?

Stu
Afrow UK is offline   Reply With Quote
Old 2nd May 2011, 11:01   #11
balamdu01
Junior Member
 
Join Date: Apr 2011
Posts: 7
Thanks for the reply.
Yes. we are writing text file (.txt files) in that path.
balamdu01 is offline   Reply With Quote
Old 2nd May 2011, 14:18   #12
Highcoder
Member
 
Join Date: Jan 2011
Posts: 69
...

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%
Highcoder is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump