Last active
August 12, 2019 07:34
-
-
Save SegoCode/29f9f6d364afeb86dca590cdb2b6f834 to your computer and use it in GitHub Desktop.
Hide console from powershell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#----------------------HIDE SCRIPT------------------------------# | |
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); | |
' | |
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } | |
$consolePtr = [Console.Window]::GetConsoleWindow() | |
[Console.Window]::ShowWindow($consolePtr, 0) | |
#----------------------------------------------------------------------# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment