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

Reply
Thread Tools Search this Thread Display Modes
Old 24th February 2017, 09:48   #1
alexmitev
Junior Member
 
Join Date: Feb 2017
Posts: 15
ExecWait fails if RequestExecutionLevel user and new process requires elevation

Hello,
I have an issue using Exec/Exec wait from a script that sets RequestExecutionLevel user and new process requires elevation. Sample code:
PHP Code:
RequestExecutionLevel user
ExecWait 
'"D:\Programs\nsis-3.01-setup.exe"' 
I tried the CreateProcess code suggested here and it returned error code ERROR_ELEVATION_REQUIRED. I digged a little more and found this article which suggests all CreateProcess() calls should be replaced by ShellExecute(). I searched the NSIS code, seems like the myCreateProcess() function has to use ShellExecute() instead of CreateProcess() ...
alexmitev is offline   Reply With Quote
Old 24th February 2017, 11:00   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,447
If you know you need elevation then it is much better to ask for it upfront.

If you insist on your current design you can use http://nsis.sourceforge.net/ShellExecWait

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 24th February 2017, 12:25   #3
alexmitev
Junior Member
 
Join Date: Feb 2017
Posts: 15
Well, if I'm running third party application, there is no way of knowing if it will need elevation. Even if I'm running my own uninstaller, the elevation requirements might change between versions.
Yes, I saw this plugin, seems it has to be used every time instead of Exec/ExecWait, at least until NSIS core code changes, which I guess won't happen ever...
alexmitev is offline   Reply With Quote
Old 25th February 2017, 02:20   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,447
Quote:
Originally Posted by alexmitev View Post
... at least until NSIS core code changes, which I guess won't happen ever...
While I agree that NSIS really should have a ExecShellWait instruction there are a couple of reasons why it has not been added yet.

1) People are going to complain that it does not always wait and I'm the one that ends up having to explain why over and over again. (A selfish reason, I know)

2) It means we would switch from ShellExecute to ShellExecuteEx and ShellExecute in shell32.dll actually calls ShellExecuteEx with a flag that Microsoft refuses to document and this flag does effect how certain things are executed! If we use the flag then we are relying on undocumented stuff that could break in the future. If we don't use the flag we break backward compatibility.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 25th February 2017, 07:32   #5
alexmitev
Junior Member
 
Join Date: Feb 2017
Posts: 15
Thank you for your reply, Anders.

I think ExecWait now calls CreateProcess + WaitForSingleObject, or I am wrong?
We don't have to change it.
If we add the new instruction ExecShellWait, it would call ShellExecuteEx(SEE_MASK_NOCLOSEPROCESS|SEE_MASK_NOASYNC) + WaitForSingleObject(INFINITE), like the plugin does.
I am using this approach now in my code and I think it always waits, as long as it's called with the SEE_MASK_NOCLOSEPROCESS|SEE_MASK_NOASYNC flags and it's called with the 'open' verb on an executable file.
I guess the reason for using ShellExecute() is that ShellExecuteEx() is supported on XP and above. I guess ExecShellWait can just fallback to ExecWait on systems older than XP, which don't have UAC anyway.
alexmitev is offline   Reply With Quote
Old 25th February 2017, 10:40   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,447
My point was that ExecShell would change and call ShellExecuteEx as well.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 27th February 2017, 10:29   #7
alexmitev
Junior Member
 
Join Date: Feb 2017
Posts: 15
Quote:
Originally Posted by Anders View Post
My point was that ExecShell would change and call ShellExecuteEx as well.
I don't see a reason to change the ExecShell implementation. You said there is going to be a new function ExecShellWait. I don't think it will call ExecShell or rely on its implementation.
alexmitev 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