how to add -noexit parameter when using EXE packager

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE 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.
This topic is 8 years and 1 month 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
jacortijo
Posts: 2
Last visit: Tue Feb 09, 2016 1:21 am

how to add -noexit parameter when using EXE packager

Post by jacortijo »

Product, version and build: PowerShell 2015 4.2.99
32 or 64 bit version of product: 64
Operating system: Win7
32 or 64 bit OS: 64

Hi,
I am doing some test with your product regarding the creation of an EXE file from a powershell script.

On my script, I register to a WMI event so I need the script to be running at all times. At the present I use this command line:
powershell.exe -nofile -windowstyle hidden -file c:\temp\myscript.ps1

when using your packager module I dont see where I could introduce this powershell parameters. is it possible somehow?

Many thanks.
Jose
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: how to add -noexit parameter when using EXE packager

Post by Alexander Riedel »

Since powershell.exe is not involved with a packaged executable, its command line parameters are not relevant.
A packaged executable never load a profile so that is easy.
If you do not want a command prompt, simply package with a Windows engine.
Maybe this will help:
https://www.sapien.com/blog/2014/03/25/ ... 14-part-1/

The title of this post implies that you want to specify -noexit, but that is contradicted by the windowsstyle hidden setting you ask for.
So I am not sure if this is something you need.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jacortijo
Posts: 2
Last visit: Tue Feb 09, 2016 1:21 am

Re: how to add -noexit parameter when using EXE packager

Post by jacortijo »

Hi alexander,
I think my question was not very clear, so better I attach a snippet of my code. Basically I register an action to the WMI event for storage USB devices. The function checks for the existence of a stamp file on the USB and do some other checks which are not included in the code.
$query = "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_LogicalDisk' AND TargetInstance.DriveType=2"

Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {

$class = $eventArgs.NewEvent.__CLASS
$device = $eventArgs.NewEvent.TargetInstance.DeviceID

$wshell = New-Object -ComObject Wscript.Shell
switch($class)
{
__InstanceCreationEvent {
$path = $device + "\STAMP.kiosk"
Write-Host "*** Checking the existence of the file $path"
if(Test-Path -Path $path)
{
Write-Host "*** Looking for the content of the file $path"
$wshell.Popup("Inserted, device id: $device WITH STAMP.kiosk",0,"Done",0x1)
}
else{
$wshell.Popup("Inserted, device id: $device WITHOUT STAMP.kiosk",0,"Done",0x1)
}
}
__InstanceDeletionEvent {
$wshell.Popup("Removed, device id: $device ",0,"Done",0x1)
}
}
}
For this script to run as I expected, I need to execute it with the -noexit -windowstyle hidden options.
powershell.exe -noexit -windowstyle hidden -file c:\temp\myscript.ps1
Basically if the powershell session is closed, the registration to the event is removed. In addition,I need the execution to be hidden in order to avoid the user be able to cancel it.

I checked the PrimalScript options and I couldn't find any option to add "-noexit" or "hidden" behaviours in the executable...
sure that I am missing something but I don't know what.

Many thanks.
jose
This topic is 8 years and 1 month 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.