Run powershell script

44 views
Skip to first unread message

Marc MENDEZ

unread,
Nov 3, 2021, 11:54:51 AM11/3/21
to innosetup
Hi,

I need to install a powershell module.
Ir requires to install the package provider Nuget

I created a ps script called "installHL7Tools.ps1" :

    Install-PackageProvider -Name Nuget -Force
    Install-Module -Force HL7Tools
I need the first line, 'cause I'm not sure the Nuget is installed on the final computer.

In mu innosetup file, I have !
[Files]
Source: "installHL7Tools.ps1";       DestDir: "{tmp}"

[Run]
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -File ""{tmp}\installHL7Tools.ps1"""; WorkingDir: {tmp}; Flags : runascurrentuser

Of course, my setup is run with admin privileges.
If I run installHL7Tools.ps1 from a powershell console window as admin, it works
But, if I run it thru my install kit , I don't find the package when I check it in a power shell console window.

What's wrong ?

Thx

Bill Stewart

unread,
Nov 3, 2021, 5:57:11 PM11/3/21
to innosetup
Per the documentation[1]:

runascurrentuser - If this flag is specified, the spawned process will inherit Setup/Uninstall's user credentials (typically, full administrative privileges). This is the default behavior when the postinstall flag is not used.
This flag cannot be combined with the runasoriginaluser flag.

runasoriginaluser - Valid only in a [Run] section. If this flag is specified, the spawned process will execute with the (normally non-elevated) credentials of the user that started Setup initially (i.e., the "pre-UAC dialog" credentials).

Accordingly, it seems you might need runasoriginaluser rather than runascurrentuser ?

Bill

Marc MENDEZ

unread,
Nov 4, 2021, 8:47:28 AM11/4/21
to inno...@googlegroups.com
Hi,

I tried :

[Run]
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -File ""{tmp}\installHL7Tools.ps1"""; WorkingDir: {tmp}; Flags : runasoriginaluser 

but it does not work : I get an error (something like "admin privileges required to run install-packageprovider")



-- 
Cordialement,

Marc MENDEZ


--
You received this message because you are subscribed to a topic in the Google Groups "innosetup" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/innosetup/WDtf_hP3W3Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to innosetup+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/innosetup/07429c83-fcc2-481c-b001-3c2f296b1fd9n%40googlegroups.com.

Bill Stewart

unread,
Nov 4, 2021, 4:05:10 PM11/4/21
to innosetup
On Thursday, November 4, 2021 at 6:47:28 AM UTC-6 Marc MENDEZ wrote:

I tried :

[Run]
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -File ""{tmp}\installHL7Tools.ps1"""; WorkingDir: {tmp}; Flags : runasoriginaluser 

but it does not work : I get an error (something like "admin privileges required to run install-packageprovider")

 So it seems that you will need to split your script into two separate executions: Run Install-PackageProvider as an elevated user, and then run Install-Module as the current user.

Bill
Reply all
Reply to author
Forward
0 new messages