GOALS: run a powershell script without showing the window (it's ok if it pops up for few seconds).
PROBLEM: the script tcplisten.ps1
works just if the window is displayed to the user. All the attempts below don't work. Because when I run netstat -ano -p tcp
, port 9999
is not listening.
tcplisten.ps1
$Listener = [System.Net.Sockets.TcpListener]9999;
$Listener.Start()
ATTEMPTS:
powershell.exe
powershell.exe -windowstyle hidden .\tcplisten.ps1
hidden -command
powershell -windowstyle hidden -command $Listener = [System.Net.Sockets.TcpListener]9999; $Listener.Start()
-NoProfile -NonInteractive -ExecutionPolicy Bypass
powershell -NoP -NonI -W Hidden -Exec Bypass -Command
Start-Process
Start-Process powershell.exe -ArgumentList "-WindowsStyle hidden -file .\tcplisten.ps1"
vbs script
Create a .vbs with this script and run it
command = "powershell.exe -nologo -command C:\Users\Utente\Desktop\tcplisten.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0
QUESTION: is there a solution? Am I doing some mistake?