Running Custom Actions

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 2 years and 2 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
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Running Custom Actions

Post by Alexander Riedel »

Well, that psbuild file has no custom actions, so there is nothing to see there in either case.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Re: Running Custom Actions

Post by B Daring »

Sorry, uploaded wrong psbuild. My bad. psbuild uploaded again.
CustomAction.png
CustomAction.png (56.85 KiB) Viewed 4069 times
Attachments
JCInventoryStandAlone.ps1.psbuild
(4.05 KiB) Downloaded 127 times
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Re: Running Custom Actions

Post by B Daring »

So now news on what I did wrong or why it doesn't work? Should I open a support ticket?
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 1:00 pm
Answers: 39
Been upvoted: 30 times

Re: Running Custom Actions

Post by brittneyr »

We are looking into this and will get back to you soon.
Brittney
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Running Custom Actions

Post by Alexander Riedel »

Took a little to piece this together. You never uploaded the psbuild file that actually has the settings for your ps1 script.
If you want to adjust per machine privileged information you need to check "Run under system account" for that specific custom action, otherwise it is not allowed to do that.

To find out what your custom actions does during install, I would suggest to modify the script temporarily so that you actually know what happens.
Place this at the end:
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');

This stops the custom action and the installer so you can see any error output.
In the provided sample from the blog post it would also be wise to remove the | Out-Null from the commands.

You can also add this to the top of any script requiring full access to the machine where it runs:

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $true)
{
# Do your thing
}
else
{
# Bitterly complain about missing privileges
}
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Re: Running Custom Actions

Post by B Daring »

Thanks Alexander,

I did upload the psbuild, it has been downloaded a lot of times, it is with the screenshot I uploaded. I will try those suggestions and let you know.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Running Custom Actions

Post by Alexander Riedel »

Yes, I saw the psbuild, but that has your custom exe (SetReg) configured not your powershell script.

[MSIActions_WinowsRun]
Name=WinowsRun
FileName=SetReg.exe
Folder=INSTALLDIR
Arguments=
ExecutionTime=1
NoImpersonation=0
WaitFinish=1
CheckReturn=0
ExecInstall=1
ExecUninstall=0
ExecMaintenance=1
[MSI Actions]
Action1=WinowsRun


Unless I misunderstood something, your original question was about powershell custom actions.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
B Daring
Posts: 90
Last visit: Mon Feb 05, 2024 3:00 pm
Answers: 2
Has voted: 1 time

Re: Running Custom Actions

Post by B Daring »

Thanks Alexander,
Yes, it had my custom reg script as I was testing everything as it didn't matter what I ran it did not work. So back to the powershell one. I did add the press any key to continue and it worked, it added the reg key. But if I take that line out it doesn't work. The prompt comes up so fast so maybe it doesn't have time to actually run the line? I don't think I have a problem with leaving the press any key, just as long as it works.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Running Custom Actions

Post by Alexander Riedel »

I cannot imagine that waiting for a key press would impede on any preceding statement. It it was quantum mechanics and this is a Heisenberg case, maybe :D
There is something else at play.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 2 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.