PrimalScript 2014 - PowerShell V3 Packger Error

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 9 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 »

Hello,

I have a script to shutdown the computer running Windows Server 2012 R2. The code is listed below:

Code: Select all

Stop-Computer -Force
When I packaged the script with "SAPIEN PowerShell V3 Host (Command line) Any platform" or "SAPIEN PowerShell V3 Host x64" engine type, the packaged script produced the following error:

ERROR: Stop-Computer : Privilege not held.
ERROR: At line:35 char:1
ERROR: + Stop-Computer -Force
ERROR: + ~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (MYCOMPUTERNAME:String) [Stop-C
ERROR: omputer], ManagementException
ERROR: + FullyQualifiedErrorId : StopComputerException,Microsoft.PowerShell.Comma
ERROR: nds.StopComputerCommand
ERROR:

However, when I packaged the script with "SAPIEN PowerShell V2 Host (Command line) Any platform" or "SAPIEN PowerShell V2 Host x64" engine type, the packaged script worked as expected - it can shutdown the computer without any problem.

This is also true with the code listed below from: http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Code: Select all

$computername= "."
$win32OS = get-wmiobject win32_operatingsystem -computername $computername
$win32OS.psbase.Scope.Options.EnablePrivileges = $true
$win32OS.win32shutdown(8)
Currently, I ended up with using the shutdown utility from Windows to perform this task.

Please let me know what I can do for the Stop-Computer cmdlet with work with PowerShell V3 packager.

Thanks.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 »

By the way, this behavior also happens with PrimalScript 2012 - extactly the same issue with SAPIEN PowerShell Host (Command line) with "Use PowerShell V3" engine type selected, but not when "Use PowerShell V3" engine type is not selected.

Thanks.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by Alexander Riedel »

As the error message indicates, the process does not have the privilege to execute that statement.
We cannot debug or determine your local security settings.
This error is reported by the powershell engine and not by the packager or the host inside the package.

Most likely you will need to elevate to obtain the proper privilege to execute that statement.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 »

Alex,

This command (Stop-Computer -Force) was launched in PowerShell V3 packaged script within an Administrator console's command prompt window.

What other elevated privilege can it be above an Administrator console?

When I just launched this cmdlet in the Administrator PowerShell console without a script, the computer will shutdown without any issue. Again, this command is launched on a Windows Server 2012 R2 computer.

When I packaged this script with the PowerShell V2 engine, the packaged script can shutdown the same computer (Windows Server 2012 R2) without any problem.

Are you saying that the PowerShell V2 engine provided a higher elevated privilege than a PowerShell V3 engine?

Why the shutdown utility from Windows Server 2012 R2 can shutdown the computer in the same Administrator command prompt?
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by Alexander Riedel »

It may have something to do with the "any platform" engine. It seems the powershell engine has issues with assemblies not tied to a specific platform.
We are investigating the problem.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 »

Thank you for the information.

By the way, this behavior also happens with Power Studio 2014 - exactly the same issue with SAPIEN PowerShell V3 Host (Command line) x64 platform packager.
User avatar
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by clum09 »

Alex,

Any news for the packaging issue with PowerShell V3 packager?

Thanks.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: PrimalScript 2014 - PowerShell V3 Packger Error

Post by Alexander Riedel »

This has nothing to do with the packager.
A little research on Google shows that there is a difference between .NET 4.0 and prior regarding the SE_SHUTDOWN_NAME privilege.

The process token needs to be adjusted for a process to have the right to shutdown a computer. PowerShell.exe does that for you, because it is a system management console.

Packaged executables do NOT have that privilege set and we will not add that per default, because it would open the door do a great number of security problems.

This post has some C# code showing how to adjust token privileges:
http://stackoverflow.com/questions/1793 ... ng-to-shut

If you really positively MUST use stop-computer from a packaged executable I suggest you incorporate code like that.

This blog post might help:
http://www.leeholmes.com/blog/2010/09/2 ... owershell/
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 9 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.