I want to execute a powershell script on the start of the electron App. I tried to add the following into the <head> in my index.html :
<head>
<script type="text/javascript">
var spawn = require("child_process").spawn;
spawn("powershell.exe",[".\myPSScript.ps1"]);
</script>
</head>
<body>
...
</body>
This did not work. When adding:
document.write("Hello")
it shows up in the app so I can be sure that the <script>is being run. When I run the script itself from powershell-terminal it runs with no issues and does what it should.
I also tried giving the absolute path in:
spawn("powershell.exe",["C:\folder\folder2\myPSScript.ps1"]);
The script deletes all .db files in a folder on the machine.
Get-ChildItem -Path 'MY_Wonderfull_Path' *.db | Where-Object { $_.CreationTime -lt (get-date 2021-09-09) } | foreach { Remove-Item -Path $_.FullName }
I have no idea why it is not running. Is electron not able to spawn a new child process? Is it an issue with permissions?
spawn("powershell.exe",["C:\\folder\\folder2\\myPSScript.ps1"]);