![]() |
#1 |
Junior Member
Join Date: Nov 2015
Posts: 1
|
ExecWait and run uninstall elevated
Hi all,
I'm trying to get an installer which uninstall previous version if needed. So, everything is ok when the windows user is admin But for a classical user, install part works well, but ExecWait never returns. code: What's wrong ? Is there another way to call the uninstaller inside the installer ? Thanks. |
![]() |
![]() |
![]() |
#2 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
If you try to start a process that requires "elevation" (i.e. admin-rights), which your Uninstaller probably does, from a "non-elevated" process (i.e. a process not running with admin rights) using a function like Exec or ExecWait, then it's just going to fail! You can use ExecShell, which will trigger an UAC dialog and, if the user agrees, launch the process. But then you can not wait for the process to finish...
I implemented the ExecShellWaitEx function for exactly that reason: http://muldersoft.com/docs/stdutils_....html#a3d3af46 My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#3 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
The UAC plug-in is difficult to use correctly so please consider a different approach.
Your code is fundamentally broken, you cannot combine RequestExecutionLevel admin and the UAC plug-in! You are not quoting the path in ExecWait and it probably should be silent. Normally I'd ask you to report your Windows, NSIS and UAC plug-in versions but your insufficient and broken example code is not worth my time trying to reproduce your problem... IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#4 | |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
Quote:
Two issues off the top of my head: A) Vista, 7 (and 8?) with UAC turned off. B) 2000, XP and 2003 with non-admin credentials used in the runas dialog. IntOp $PostCount $PostCount + 1 |
|
![]() |
![]() |
![]() |
#5 | ||
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
Quote:
But: Using ShellExecute(Ex) it's at least possible to start a process that requires "elevation" from a non-elevated process (and if user declined, you can detect the issue and just retry) - whereas Exec or ExecWait just fail in that situation with error #740. See also: http://blogs.msdn.com/b/winsdk/archi...plication.aspx I think if UAC is turned off, then ShellExecute(Ex) just launches the "elevated" process without showing the UAC dialog. In this special situation Exec or ExecWait could do the job too, but they'd start failing as soon as UAC is actually not turned off on some computer. ShellExecute(Ex), on the other hand, works fine under both conditions, I believe. Quote:
If a "non-admin" user launches your installer on any of these systems (or an "admin" user uses run as to run your installer under a "non-admin" account), you have a problem anyway! The installer needs to detect this via UserInfo plug-in and abort... My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
||
![]() |
![]() |
![]() |
#6 | ||
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
Quote:
Quote:
IntOp $PostCount $PostCount + 1 |
||
![]() |
![]() |
![]() |
#7 | |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
Quote:
I did not say that it (necessarily) does "start something elevated". What I actually said is that it allows for launching a process that requires elevation (as per its Manifest) from a non-elevated process. In that case Exec and ExecWait would just fail. My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
|
![]() |
![]() |
![]() |
#8 | |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
Quote:
ShellExecuteEx works in all cases depending on your definition of working. It works differently depending on the system configuration which obviously is not a good thing. The OP wants to start a new process with administrator rights and a simple ShellExecuteEx is not enough because there are several corner cases you need to handle. Only a plugin with a specific RunAsAdmin type function can accomplish this in a satisfactory fashion. IntOp $PostCount $PostCount + 1 |
|
![]() |
![]() |
![]() |
#9 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
If I understood the OP right, he wants to launch an uninstaller from his "main" installer - which works from elevated ("admin") user context, but not from non-elevated ("classical") user context. So, it sounds to me like the typical "unable to start a process that requires elevation from non-elevated process" (code #740) problem. The uinstaller probably requires elevation, as per its Manifest, so Exec or ExecWait are going to fail when the "main" installer is not already elevated. The ExecShellWaitEx function can resolve that problem.
If we are running on a "legacy" system without UAC, there is no such thing as "elevation". So there are only two possibilities: Either the current (logged on) user is an "admin" user, or not. Consequently, the only thing that really can be done by an (un)installer that requires "admin" rights is: Detect the current user-type via UserInfo plug-in – and abort with error if the current user is not an "admin" user. My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#10 | ||
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,358
|
![]() Quote:
Quote:
IntOp $PostCount $PostCount + 1 |
||
![]() |
![]() |
![]() |
|
Tags |
auto, elevated, execwait, uninstall |
Thread Tools | Search this Thread |
Display Modes | |
|
|