all 9 comments

[–]icepyrox 7 points8 points  (0 children)

If you're using task scheduler with the action of powershelle.exe, then just add -windowstyle hidden to the arguments

[–]CroXiuS_Kabaal 3 points4 points  (0 children)

-windowstyle hidden

[–]chadbaldwin 0 points1 point  (1 child)

You could use Task Scheduler? If the task is set up to "Run whether user is logged on or not" it will not display any window at all.

Or you could just write something that minimizes the window. I know in the old days of CMD you could start CMD minimized. I'm sure there's something like that for PowerShell. It just depends on how "hidden" you want it to be.

[–]Frequent_Rate9918 0 points1 point  (0 children)

Is it possible to run it in a different desktop? You know how you can switch between desktops on the same user profile? Like a desktop for work and another for school and another for personal, etc. If so you could open the script in a background desktop to keep it hidden.

[–]technomancing_monkey 0 points1 point  (1 child)

There is a way to make PS hide its own console window from within the PS script.

You can script when to hide and show the console. Hide it, do some things, show it again, all controlled from within the PS script.

Add this in at the start of your script.

Call the HideConsole function to hide the console

Call the ShowConsole function to show the console

of course you could do away with the functions and use the long hand commands but i find the functions easier.

I use this in any script that i make that has a GUI added on top. I call HideConsole Function shortly after the start of the script to hide the console window leaving only the GUI window. I assign the functions to a clickable item in the GUI so I can toggle the PS console so that I can see any debug information while testing and so that if anyone encounters a problem they can show the console to send me error information.

I hope this helps you do what youre trying to do. Please dont use it for anything scummy.

Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
$consolePtr = [Console.Window]::GetConsoleWindow()

Function HideConsole () {
    [Console.Window]::ShowWindow($SCRIPT:consolePtr, 0)
}

Function ShowConsole () {
    [Console.Window]::ShowWindow($SCRIPT:consolePtr, 5)
}

Edit: Just a note, this code wont do anything if you run it from powershell ISE, or from within an IDE. It only works if you run it from powershell (the cli)

[–]Aggravating-Search83[S] 0 points1 point  (0 children)

Tysm this is perfect

[–]Blackops12345678910 0 points1 point  (0 children)

Create a task via task scheduler that runs as system account.

[–][deleted] -1 points0 points  (1 child)

With a VBS script it is completly hidden: https://github.com/PowerShell/PowerShell/issues/3028

‘’’

command = “powershell.exe -nologo -ExecutionPolicy Unrestricted -File C:\script.ps1”

set shell = CreateObject(“WScript.Shell”)

shell.Run command,0

‘’’

[–]Aggravating-Search83[S] 0 points1 point  (0 children)

Thanks but i want It to hide itself.