Old 30th September 2011, 15:59   #1
installer32
Junior Member
 
Join Date: May 2009
Posts: 8
ShellExecAsUser plugin

I've created a new ShellExecAsUser plugin:
http://nsis.sourceforge.net/ShellExecAsUser_plug-in
It allows to execute the specified program in non-admin context, i.e. it is intended for installers that run with admin rights but need to execute something in non-admin context.
It uses desktop COM interface to execute process, so that process is launched by explorer (http://brandonlive.com/2008/04/27/ge...ou-part-2-how/).
Any comments are welcome.
installer32 is offline   Reply With Quote
Old 1st October 2011, 11:32   #2
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Sound like something that can pretty useful

Two questions:
* What operating systems does it work with? Any "fall back" mode for WinXP and Win2k?
* Can you please compile a Unicode version of that plug-in?

(Sorry, did not have time to examine your code yet)

Regards,
MuldeR.

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 1st October 2011, 14:04   #3
installer32
Junior Member
 
Join Date: May 2009
Posts: 8
Quote:
* What operating systems does it work with? Any "fall back" mode for WinXP and Win2k?
It should work starting from Win2k. On WinXP, Win2k (or if UAC is disabled) the plugin will do the launch using ShellExecute.

Quote:
* Can you please compile a Unicode version of that plug-in?
Ok I'll do.
installer32 is offline   Reply With Quote
Old 1st October 2011, 14:25   #4
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Thank you!

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 1st October 2011, 16:13   #5
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
I have adopted your ExecShellAsUser method into my StdUtils plug-in:
http://pastie.org/private/b9cymlmclyuo6b1f4kcmfg

(ANSI and Unicode builds attached)
Attached Files
File Type: zip StdUtils.2011-10-01.zip (90.8 KB, 196 views)

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 1st October 2011, 17:07   #6
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
So, what, does this do what the UAC plugin was also designed to do, but without two installer instances?
MSG is offline   Reply With Quote
Old 1st October 2011, 17:15   #7
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
Originally Posted by MSG View Post
So, what, does this do what the UAC plugin was also designed to do, but without two installer instances?
Yup. It generates a non-elevated process right from the elevated installer instance.

Seems to work for me on Windows 7 (x64). I don't have any other UAC-enabled test platforms.

On Windows XP and earlier it simply falls back to the normal ShellExecute()...

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 1st October 2011, 17:27   #8
installer32
Junior Member
 
Join Date: May 2009
Posts: 8
Quote:
I have adopted your ExecShellAsUser method into my StdUtils plug-in:
Ok but note that I used another thread for desktop COM calls. Otherwise I (sometimes) got RPC_E_CANTCALLOUT_ININPUTSYNCCALL error, which is solved if you do it on another thread.
installer32 is offline   Reply With Quote
Old 1st October 2011, 17:30   #9
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
Originally Posted by installer32 View Post
Ok but note that I used another thread for desktop COM calls. Otherwise I (sometimes) got RPC_E_CANTCALLOUT_ININPUTSYNCCALL error, which is solved if you do it on another thread.
Thanks for the hint!

(I already noticed that CoInitializeEx() fails, because, I think, COM already is initialized with other parameters for the calling thread. So I switched back to CoInitialize() again. But I will implement your suggestion now)

[UPDATE] Done. New version is attached. [/UPDATE]
Attached Files
File Type: zip StdUtils.2011-10-01.Update-1.zip (91.5 KB, 161 views)

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI

Last edited by LoRd_MuldeR; 1st October 2011 at 18:49.
LoRd_MuldeR is offline   Reply With Quote
Old 1st October 2011, 19:49   #10
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Very cool! I use the UAC plugin for double install mode all-through, for which case I guess it is more convenient to have two instances. But this is a very cool alternative, and a lot simpler to use!
MSG is offline   Reply With Quote
Old 2nd October 2011, 12:01   #11
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Small update:
http://nsis.sourceforge.net/StdUtils...xecShellAsUser
Attached Files
File Type: zip StdUtils.2011-10-02.zip (95.8 KB, 154 views)

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI

Last edited by LoRd_MuldeR; 2nd October 2011 at 13:31.
LoRd_MuldeR is offline   Reply With Quote
Old 2nd October 2011, 17:13   #12
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Sorry, here are some more fixes:
Attached Files
File Type: zip StdUtils.2011-10-02.Update-1.zip (96.8 KB, 191 views)

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 2nd October 2011, 19:46   #13
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,891
This COM hack is problematic and/or broken when:

A)
Explorer is not running

B)
Explorer is elevated (Rare, but some people do it)

C)
Desktop user is not the correct parent:
User A is logged on,
runs setup as non-admin user B with runas.exe,
setup is elevated with user C;
The correct user is B, not A.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd October 2011, 20:40   #14
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
In case (A) it will fall back to the normal ShellExecute(). Not ideal, but well...

I'm not sure what will happen in case (B) or how to reproduce this, but I guess in that case we will either fail to get the COM interface and thus fall back to the normal ShellExecute(), or we will simply create an elevated instance.

Again not ideal, but if you run your Explorer in an elevated way, then problems are preprogrammed anyway

(And in case (C) it may depend on the situation/purpose whether user A or B is the "correct" one)

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 2nd October 2011, 20:42   #15
installer32
Junior Member
 
Join Date: May 2009
Posts: 8
Anders
You are right and I'll add your remarks to plugin description, though I think it's quite uncommon and as such these limitations are acceptable to many people.
installer32 is offline   Reply With Quote
Old 9th October 2011, 15:34   #16
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
I have updated my StdUtils plug-in to use the "new" plug-in API, i.e. get rid of explicit unload.

Furthermore I added a version of ExecShell with wait capability as well as some more convenience functions.

New version here:
http://nsis.sourceforge.net/StdUtils_plug-in

(BTW: Could some mod please delete the obsolete versions attached to my previous posts?)

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 21st October 2012, 17:21   #17
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
In case somebody is interested, I just uploaded a new version of my StdUtils plug-in:
http://nsis.sourceforge.net/StdUtils_plug-in

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 23rd October 2012, 00:20   #18
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Quote:
Originally Posted by LoRd_MuldeR View Post
In case somebody is interested, I just uploaded a new version of my StdUtils plug-in:
http://nsis.sourceforge.net/StdUtils_plug-in
I've just uploaded yet another update, which fixes a potential crash related to CoUninitialize() and certain certain Shell Extensions. In my case it was Tortoise GIT. Put simply, CoUninitialize() might still crash, even if all COM interfaces were released properly before. Happens if there are outstanding messages. It turns out we must dispatch all pending messages explicitly before calling CoUninitialize().

As this might be relevant for all NSIS plug-in's that deal with COM interfaces (and the Shell), you might want to have a look here:
http://stackoverflow.com/questions/1...itialize-crash

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 28th July 2015, 14:23   #19
Theresias
Junior Member
 
Join Date: Jun 2006
Posts: 48
(As requested in the NSIS WIKI, I'm using this topic for feedback on StdUtils.)

LoRd_MuldeR, any plans to add a x86/x64 check to StdUtils? I am currently using...

code:
System::Call "kernel32::GetCurrentProcess() i .s"
System::Call "kernel32::IsWow64Process(i s, *i .r0)"



...but maybe there is a cleaner way to do this?
Theresias is offline   Reply With Quote
Old 28th July 2015, 14:27   #20
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
NSIS has that built-in already

code:
!include "LogicLib.nsh"
!include "x64.nsh"

${If} ${RunningX64}
MessageBox MB_OK "We are running on x64!"
${EndIf}


My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 28th July 2015, 14:37   #21
Theresias
Junior Member
 
Join Date: Jun 2006
Posts: 48
LOL Nice, thanks. Back in the day that didn't exist...
Theresias is offline   Reply With Quote
Old 28th July 2015, 16:05   #22
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,891
Quote:
Originally Posted by Theresias View Post
The system::call code is still the same behind the scenes

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 26th September 2018, 13:02   #23
r2du-soft
Senior Member
 
r2du-soft's Avatar
 
Join Date: Nov 2013
Location: Iran
Posts: 272
Question ShellExecAsUser not work in nsis unicode

hi

i use from ShellExecAsUser plugin for open the exe files run as user

Plugin:
http://nsis.sourceforge.net/ShellExecAsUser_plug-in


when i use the nsis ansi then ShellExecAsUser plugin works correctly and exe file opened.

HTML Code:
Section
ShellExecAsUser::ShellExecAsUser "open" "C:\1.exe"
SectionEnd
but if use from the nsis unicode:

HTML Code:
[B]Unicode true
[/B]
Section
ShellExecAsUser::ShellExecAsUser "open" "C:\1.exe"
SectionEnd

plugin unable to open file and show message:

Attached Thumbnails
Click image for larger version

Name:	2018-09-26_16-31-35.jpg
Views:	57
Size:	22.3 KB
ID:	54022  
r2du-soft is offline   Reply With Quote
Old 26th September 2018, 15:05   #24
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,891
There is no Unicode version of that plug-in. Try contacting the author.

Edit: A Unicode version has now been added to the wiki by the author.

IntOp $PostCount $PostCount + 1
Anders 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