Page 1 of 1

how to add -noexit parameter when using EXE packager

Posted: Mon Feb 08, 2016 3:24 am
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

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.

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

Posted: Mon Feb 08, 2016 10:30 am
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: ... 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.

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

Posted: Tue Feb 09, 2016 2:20 am
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
__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)
$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.