To help you better we need some information from you.
*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: Powershell Studio 2019 Version 5.6.167
32 or 64 bit version of product: 64bit
Operating system: Windows 10 Build 1709
32 or 64 bit OS: 64bit
*** Please add details and screenshots as needed below. ***
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
Hi all
I have a script that I have been building into an exe with Powershell Studio 2019
The script runs without errors and the cctk file will be found.
But, when I build into an executable, the source location can’t be found.
Is this a known issue or is there an an error in the script?
Best regards,
Daniel
function Get-ScriptDirectory
{
[OutputType([string])]
param ()
if ($host.Name -eq 'PrimalScriptHostImplementation')
{
if ($null -ne $hostinvocation)
{
Split-Path $hostinvocation.MyCommand.path
}
else
{
Split-Path $script:MyInvocation.MyCommand.Path
}
}
else
{
$PSScriptRoot
}
}
[string]$PSScriptRoot = Get-ScriptDirectory
function Get-PasswordIsSet
{
if ((Test-Path (Join-Path -Path $PSScriptRoot -ChildPath "cctk\cctk.exe")) -eq $true)
{
write-host 'File exist' -ForegroundColor Red
}
$proc = (Start-Process -FilePath `"$(Join-Path -Path $PSScriptRoot -ChildPath "cctk" | Join-Path -ChildPath "cctk.exe")`" -ArgumentList "--setuppwd=" -Wait -PassThru); $proc.WaitForExit(); $ExitCode = $proc.ExitCode;
Write-Host $ExitCode -ForegroundColor Red
}
Get-PasswordIsSet
Get-ScriptDirectory function and Join-Path in exe
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.
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.
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
Get-ScriptDirectory function and Join-Path in exe
- Attachments
-
- PSScriptRoot.png (69.82 KiB) Viewed 2215 times
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Get-ScriptDirectory function and Join-Path in exe
It has something to do with re-setting $PSScriptRoot. It seems Powershell in some instances does not like that.
Using a different variable name solves the problem.
Using a different variable name solves the problem.
Code: Select all
function Get-ScriptDirectory
{
[OutputType([string])]
param ()
if ($host.Name -eq 'PrimalScriptHostImplementation')
{
if ($null -ne $hostinvocation)
{
Split-Path $hostinvocation.MyCommand.path
}
else
{
Split-Path $script:MyInvocation.MyCommand.Path
}
}
else
{
$PSScriptRoot
}
}
[string]$MyScriptFolder = Get-ScriptDirectory
$MyScriptFolder
function Get-PasswordIsSet
{
if ((Test-Path (Join-Path -Path $MyScriptFolder -ChildPath "cctk\cctk.exe")) -eq $true)
{
write-host 'File exist' -ForegroundColor Red
}
#$proc = (Start-Process -FilePath `"$(Join-Path -Path $PSScriptRoot -ChildPath "cctk" | Join-Path -ChildPath "cctk.exe")`" -ArgumentList "--setuppwd=" -Wait -PassThru); $proc.WaitForExit(); $ExitCode = $proc.ExitCode;
#Write-Host $ExitCode -ForegroundColor Red
}
Get-PasswordIsSet
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- DanielLeber
- Posts: 20
- Last visit: Thu May 18, 2023 8:36 am
Re: Get-ScriptDirectory function and Join-Path in exe
it could be quite simple
Thank you for your quick response!
Thank you for your quick response!