I have a script that contains 2 files:
users.csv
script.ps1
I transfer both files to client computer and run the script.ps1
at the end of the script it runs these commands:
Remove-Item .\users.csv -Force
Remove-Item $PSCommandPath -Force
the result is that when it finished running it deletes both files from client computer as part of the script.
when I try to compile the PS1 file to EXE using Sapien powershell studio it is able to delete the CSV file but not the script file (EXE file)
is there a way to force him to do so ?
thanks
David
script file "self destruct" on compiled EXE file
Forum rules
Do not post any licensing information in this forum.
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 any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- sivandavid
- Posts: 14
- Last visit: Wed Jun 21, 2023 3:45 am
Re: script file "self destruct" on compiled EXE file
No. The file you are running is in the EXE so that would make no sense. There would be no PS1 file in the folder. Why would you copy a PS1 and embed the same file into an EXE?
- sivandavid
- Posts: 14
- Last visit: Wed Jun 21, 2023 3:45 am
Re: script file "self destruct" on compiled EXE file
I don't copy both the ps1 and EXE
I want to use instead of
users.csv
script.ps1
to compile the PS1 to EXE and then use only
users.csv
script.exe
but the command (from within the EXE)
Remove-Item $PSCommandPath -Force
don't delete the the EXE file
any idea how to force it ? or use a different command ?
I want to use instead of
users.csv
script.ps1
to compile the PS1 to EXE and then use only
users.csv
script.exe
but the command (from within the EXE)
Remove-Item $PSCommandPath -Force
don't delete the the EXE file
any idea how to force it ? or use a different command ?
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: script file "self destruct" on compiled EXE file
You cannot delete an executable file that is in use. Not from the inside.
Here is a discussion on the subject:
https://stackoverflow.com/questions/160 ... executable
Here is a discussion on the subject:
https://stackoverflow.com/questions/160 ... executable
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.