sachingaikwad
Enthusiast
Enthusiast

Invoke-VMScript install App as an administrator

Jump to solution

My requirement is to install app using msiexec, I have referred

Re: Invoke-VMScript to run ps commands as an administrator

and other posts on this forum and tried the solution mentioned but am still getting few errors. I have tried all these below options after disabling UAC.

I tried following options:

Option1:

$ScriptBlock = @"

`$proc = Start-Process -PassThru -FilePath `"c:\windows\system32\msiexec`" -ArgumentList `" /i C:\Users\XRAY\MyApp.msi /qb /norestart /passive HASH=b64ba17a00ee671df MyAppParam2=Param2 MyAppParam3=Param3 MyApp=support@MyApp.com /L*V C:\Users\XRAY\install.log`" -Wait

return `$proc.ExitCode

"@

Invoke-VMScript -VM $TARGET_VM -ScriptText $ScriptBlock

Output: 1603 error - A fatal error occurred during installation. But if I try the same command on the VM powershell it works fine.

Option2: Tried with elevated access as I need to move a file from home directory to

$ScriptBlock = @"

function Elevate-Process  {

param ([string]`$exe = `$(Throw "Pleave provide the name and path of an executable"),[string]`$arguments)

`$startinfo = new-object System.Diagnostics.ProcessStartInfo

`$startinfo.FileName = `$exe

`$startinfo.Arguments = `$arguments

`$startinfo.verb = `"RunAs`"

`$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments `"-noninteractive -command msiexec  /i C:\Users\XRAY\MyApp.msi /qb /norestart /passive HASH=b64ba17a00ee671df MyAppParam2=Param2 MyAppParam3=Param3 MyApp=support@MyApp.com /L*V C:\Users\XRAY\install.log`"

"@

Invoke-VMScript -VM $TARGET_VM -ScriptText $ScriptBlock

Output: Exception calling "Start" with "1" argument(s): "This operation requires an interactive window station"

Any suggestions please?

1 Solution

Accepted Solutions
sachingaikwad
Enthusiast
Enthusiast

User account control settings was set to "Never notify" but was still getting the "This operation requires an interactive window station" error. Looks like just disabling from UI was not sufficient so  updated HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA=0 and restarted the machine.

Note: due to the EnableLUA=0, now 'cmd+r' always opens with Admin access. Refer screenshot:

Screen Shot 2020-06-07 at 5.33.00 PM.png

Now the "This operation requires an interactive window station" error is not getting displayed anymore and MSIEXEC installation is working fine.

Command which worked: Re: Invoke-VMScript install App as an administrator

As part of my automation to work, I need to download latest MSI file and a supporting exe file from Jfrog artifactory. Using Jfrog cli, I'm downloading both msi & exe, I need to move the exe to Program Files\MyApp folder. Even though MSI installation is working now, moving file part is not working which also needs elevated access. Any suggestions please?

This is the command I'm using:

$ScriptBlock = @"

function Elevate-Process  {

param ([string]`$exe = `$(Throw "Pleave provide the name and path of an executable"),[string]`$arguments)

`$startinfo = new-object System.Diagnostics.ProcessStartInfo

`$startinfo.FileName = `$exe

`$startinfo.Arguments = `$arguments

`$startinfo.verb = `"RunAs`"

`$startinfo.UseShellExecute = `"False`"

`$startinfo.CreateNoWindow = `"True`"

`$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments `"-noninteractive -command Get-Process move C:\Users\XRAY\Delete.txt C:\PROGRA~1\MyApp\"

"@

ScriptOutput is blank.

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership

The error in option 1 is normal.

That 1603 states "Error #1603 is a Windows error that comes up during installation if a security policy on the computer has been enabled. You can adjust the setting to allow you to install but you will have to login as an Administrator to make the changes."

For option2.
Did you already try changing the /qb to /qn?

The b stands for basic UI, while the n stands for no UI.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sachingaikwad
Enthusiast
Enthusiast

@LucD tried with /qn and getting the same error "Exception calling "Start" with "1" argument(s): "This operation requires an interactive window station"

0 Kudos
LucD
Leadership
Leadership

Does this version make a difference?

$ScriptBlock = @"

function Elevate-Process  {

param ([string]`$exe = `$(Throw "Pleave provide the name and path of an executable"),[string]`$arguments)

`$startinfo = new-object System.Diagnostics.ProcessStartInfo

`$startinfo.FileName = `$exe

`$startinfo.Arguments = `$arguments

`$startinfo.verb = `"RunAs`"

`$startinfo.UseShellExecute = False

`$startinfo.CreateNoWindow = True

`$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments `"-noninteractive -command msiexec  /i C:\Users\XRAY\MyApp.msi /qb /norestart /passive HASH=b64ba17a00ee671df MyAppParam2=Param2 MyAppParam3=Param3 MyApp=support@MyApp.com /L*V C:\Users\XRAY\install.log`"

"@


Invoke-VMScript -VM $TARGET_VM -ScriptText $ScriptBlock


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

sachingaikwad
Enthusiast
Enthusiast

Below error was getting displayed

$startinfo.UseShellExecute = False

|  +                              ~~~~~

|      + CategoryInfo          : ObjectNotFound: (False:String) [], CommandNotFoundException

So modified the command to

`$startinfo.UseShellExecute = "False"

`$startinfo.CreateNoWindow = "True"

Still getting the same error:

Exception calling "Start" with "1" argument(s): "This operation requires an interactive window station"                            

|  At line:9 char:1

|  + $process = [System.Diagnostics.Process]::Start($startinfo)

|  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

|      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

|      + FullyQualifiedErrorId : Win32Exception

0 Kudos
LucD
Leadership
Leadership

What kind of MSI file is that?
A commercial product or an inhouse one?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sachingaikwad
Enthusiast
Enthusiast

This MSI is an in-house product. I tried this command which needs elevated access and it throws the same error - Exception calling "Start" with "1" argument(s): "This operation requires an interactive window station"

$ScriptBlock = @"

function Elevate-Process  {

param ([string]`$exe = `$(Throw "Pleave provide the name and path of an executable"),[string]`$arguments)

`$startinfo = new-object System.Diagnostics.ProcessStartInfo

`$startinfo.FileName = `$exe

`$startinfo.Arguments = `$arguments

`$startinfo.verb = `"RunAs`"

`$startinfo.UseShellExecute = `"False`"

`$startinfo.CreateNoWindow = `"True`"

`$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments `"-noninteractive -command Get-Process move C:\Users\XRAY\Delete.txt C:\PROGRA~1\Git\"

"@

0 Kudos
sachingaikwad
Enthusiast
Enthusiast

User account control settings was set to "Never notify" but was still getting the "This operation requires an interactive window station" error. Looks like just disabling from UI was not sufficient so  updated HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA=0 and restarted the machine.

Note: due to the EnableLUA=0, now 'cmd+r' always opens with Admin access. Refer screenshot:

Screen Shot 2020-06-07 at 5.33.00 PM.png

Now the "This operation requires an interactive window station" error is not getting displayed anymore and MSIEXEC installation is working fine.

Command which worked: Re: Invoke-VMScript install App as an administrator

As part of my automation to work, I need to download latest MSI file and a supporting exe file from Jfrog artifactory. Using Jfrog cli, I'm downloading both msi & exe, I need to move the exe to Program Files\MyApp folder. Even though MSI installation is working now, moving file part is not working which also needs elevated access. Any suggestions please?

This is the command I'm using:

$ScriptBlock = @"

function Elevate-Process  {

param ([string]`$exe = `$(Throw "Pleave provide the name and path of an executable"),[string]`$arguments)

`$startinfo = new-object System.Diagnostics.ProcessStartInfo

`$startinfo.FileName = `$exe

`$startinfo.Arguments = `$arguments

`$startinfo.verb = `"RunAs`"

`$startinfo.UseShellExecute = `"False`"

`$startinfo.CreateNoWindow = `"True`"

`$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments `"-noninteractive -command Get-Process move C:\Users\XRAY\Delete.txt C:\PROGRA~1\MyApp\"

"@

ScriptOutput is blank.

View solution in original post

0 Kudos
LucD
Leadership
Leadership

Why does the command start with Get-Process?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

sachingaikwad
Enthusiast
Enthusiast

Thank you LucD, after removing the 'Get-Process' from the command, it started working.

Below is the move file command:

$ScriptBlock = @"

function Elevate-Process  {

param ([string]`$exe = `$(Throw "Pleave provide the name and path of an executable"),[string]`$arguments)

`$startinfo = new-object System.Diagnostics.ProcessStartInfo

`$startinfo.FileName = `$exe

`$startinfo.Arguments = `$arguments

`$startinfo.verb = `"RunAs`"

`$startinfo.UseShellExecute = `"False`"

`$startinfo.CreateNoWindow = `"True`"

`$process = [System.Diagnostics.Process]::Start(`$startinfo)

}

Elevate-Process -Exe powershell.exe -Arguments `"-noninteractive -command move C:\Users\XRAY\Delete.txt C:\PROGRA~1\MyApp\"

"@

0 Kudos