Skip to content

Commit 905485c

Browse files
authored
Update README.md
1 parent 9c6c58e commit 905485c

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
1-
# HiddenPowershell
2-
Run powershell.exe hidden; since `-WindowStyle Hidden` isn't sufficient.
1+
This vbscript will run powershell.exe hidden; since [`-WindowStyle Hidden` isn't sufficient](https://github.com/PowerShell/PowerShell/issues/3028). Hopefully we'll have [a `pwshw.exe` soon](https://github.com/PowerShell/PowerShell/issues/3028#issuecomment-367169480) and this repo can be antiquated.
2+
3+
You're probably here because you've already realized that using [PowerShell's `-WindowStyle Hidden` parameter](https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help#parameters) without this script, doesn't completely hide the powershell console.
4+
5+
# Usage
6+
7+
**Do not use `cscript.exe`; it will cause a console window to appear.**
8+
9+
```
10+
wscript.exe HiddentPowershell.vbs -ExecutionPolicy ByPass -File "C:\Program Files\Get-HelloWorld.ps1"
11+
```
12+
13+
This Will run Powershell in a completely hidden console by calling PoweRShell like this:
14+
```
15+
powershell.exe -ExecutionPolicy ByPass -File "C:\Program Files\Get-HelloWorld.ps1"
16+
```
17+
18+
I recommend that you also pass the `-WindowStyle Hidden` parameter, so that the executing powershell script knows that it's hidden.
19+
20+
If you have machines that have Windows Scripting Host (WSH) file extensions (like `.vbs`) disassociated from WSH; then you will need to add the `//E:vbscript` parameter:
21+
```
22+
wscript.exe //E:vbscript HiddentPowershell.vbs ...
23+
```
24+
25+
# Logging
26+
27+
Logging is done to *Event Viewer*. There will be two events for every run of the script. One at the start of the run, and the other at the completion/finish. The details of the logs are:
28+
29+
- **Event Path:** `Windows Logs\Application`
30+
- **Source:** `WSH`
31+
- **Event ID:** *Depends on Status*
32+
- *Success*: `0` Script Finished; Powershell Exited with `0`.
33+
- *Error*: `1` Script Finished; Powershell Exited with something other than `0`.
34+
- *Information*: `4` Script Starting
35+
36+
## Start
37+
38+
The *Event ID* of the *starting* message will always be `4` (informational). Here's an example of what that will look like:
39+
40+
```
41+
HiddenPowershell Running:
42+
C:\Temp\HiddenPowershell.vbs
43+
powershell.exe -WindowStyle Hidden -ExecutionPolicy ByPass -Command Write-Host "Hello World!"
44+
```
45+
46+
## Finish
47+
48+
The *Event ID* of the *finished* message will be `0` (success). If powershell exits with a non-zero exit code, the *Event ID* will be `1` (error).
49+
50+
Here's an example of what a *success* looks like; *Event ID* is `0`:
51+
```
52+
HiddenPowershell Exited:
53+
C:\Temp\HiddenPowershell.vbs
54+
powershell.exe -WindowStyle Hidden -ExecutionPolicy ByPass -Command Write-Host "Hello World!"
55+
Exit Code: 0
56+
```
57+
58+
Here's an example of what an *error* looks like; *Event ID* is `1`:
59+
```
60+
HiddenPowershell Exited:
61+
C:\Temp\HiddenPowershell.vbs
62+
powershell.exe -WindowStyle Hidden -ExecutionPolicy ByPass -File ScriptDoesNotExist.ps1
63+
Exit Code: -196608
64+
```

0 commit comments

Comments
 (0)