0

I am currently working on creating a GUI-based application that involves calling Start-Process with specific parameters. The application works as expected when executed in both PowerShell.exe and ISE. However, I am encountering a problem when attempting to wrap the scripts (TEST1.PS1 + TEST2.PS1 + Cred Module) into an executable using IExpress.

When I run the executable, I encounter a flashing screen with no visible output before the window closes. Interestingly, I don't receive any error messages in the output or the Event Viewer.

Here's a simplified version of the code I'm using:

TEST1.PS1

    $userwho1 = whoami
    Import-Module "$PSScriptRoot\CredentialManager.psm1"
    $credential = Get-StoredCredential "MYADMIN"
    $fileExists = Test-Path -Path "$PSScriptRoot\TEST2.ps1"
    if ($fileExists) {
    Write-Host "The file exists: $PSScriptRoot\TEST2.ps1"
    $Release = "$PSScriptRoot\TEST2.ps1"
   } else {
    Write-Host "The file does not exist."
   }
    Start-Process -FilePath 
  'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' 
    -WindowStyle hidden -ArgumentList "-executionpolicy bypass -File 
   $Release $userwho1" -Credential $credential -WorkingDirectory 
    'C:\Windows\System32'

Here is a screenshot confirming that the script is in place and detected at runtime.

Path confirmation

My expectation is that Start-Process should call TEST2.PS1 (a user form) with the privileges of the MYADMIN domain user.

Additional Information:

PowerShell version: 5.1 I suspect that the issue might be related to how I'm wrapping the scripts using IExpress. Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated. Thank you!

cri ron
  • 1
  • 2
  • 1
    Iexpress is setting the folder to TEMP space. In IExpress use CD to move to a known folder before running. – jdweng Aug 14 '23 at 12:19
  • As mentioned by @jdweng, don't use `$PSScriptRoot`but: `$MyInvocation.MyCommand.CommandType -eq "ExternalScript") { $ScriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition } else { $ScriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) ; if (!$ScriptPath){ $ScriptPath = "." } }`. Besides, are you running this under the same account as you tested it? Or under the SYSTEM account? – iRon Aug 14 '23 at 14:30
  • I have tried changes as you suggested but no luck. Same problem as it was. However as @jdweng suggested, I tried to extract the files from Temp to a common Folder and Hard coded the path and that worked. ( But I was trying to not to set a hard coded path at the first place) I have tested it using by domain account . So basically 1. i am calling Test1.Ps1 as user account 2. I am elevating TEST2.Ps1 using cred of more privileged account to perform final task . Both are domain accounts – cri ron Aug 14 '23 at 15:20
  • Please can you post the output returned from `[Environment]::GetCommandLineArgs()`, when its running via the exe – KG-DROID Aug 14 '23 at 20:03

0 Answers0