Skip to content

Commit 9c6c58e

Browse files
authored
Added HiddenPowershell.vbs
1 parent 9a088d9 commit 9c6c58e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

HiddenPowershell.vbs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
' Usage:
2+
' wscript.exe //E:vbscript HiddentPowershell.vbs -ExecutionPolicy ByPass -File "C:\Program Files\Get-HelloWorld.ps1"
3+
'
4+
' Will run Powershell in a hidden console, like this:
5+
' powershell.exe -ExecutionPolicy ByPass -File "C:\Program Files\Get-HelloWorld.ps1"
6+
'
7+
' I recommend that you also pass the `-WindowStyle Hidden` parameter,
8+
' so that the executing powershell script knows that it's hidden.
9+
' Using `-WindowStyle Hidden` without this script, doesn't completely hide
10+
' the powershell console.
11+
'
12+
' More Info: https://github.com/UNT-CAS/HiddenPowershell
13+
14+
Set oShell = CreateObject("Wscript.Shell")
15+
16+
Const LOG_EVENT_SUCCESS = 0
17+
Const LOG_EVENT_ERROR = 1
18+
Const LOG_EVENT_INFORMATION = 4
19+
20+
Dim iExitStatus : iExitStatus = LOG_EVENT_SUCCESS
21+
Dim sArgs : sArgs = "powershell.exe"
22+
Dim sMessage : sMessage = ""
23+
24+
For Each sArg in Wscript.Arguments
25+
If InStr(sArg, " ") > 0 Then
26+
' If there's a space in the argument, wrap it in quotes.
27+
sArgs = sArgs &" """& sArg &""""
28+
Else
29+
sArgs = sArgs &" "& sArg
30+
End If
31+
Next
32+
33+
sMessage = "HiddenPowershell Running: " _
34+
& vbCrLf & vbTab & Wscript.ScriptFullName _
35+
& vbCrLf & vbTab & sArgs
36+
oShell.LogEvent LOG_EVENT_INFORMATION, sMessage
37+
38+
iReturn = oShell.Run(sArgs, 0, False)
39+
40+
If iReturn <> 0 Then
41+
iExitStatus = LOG_EVENT_ERROR
42+
End If
43+
44+
sMessage = "HiddenPowershell Exited: " _
45+
& vbCrLf & vbTab & Wscript.ScriptFullName _
46+
& vbCrLf & vbTab & sArgs _
47+
& vbCrLf & vbTab & "Exit Code: " &iReturn
48+
oShell.LogEvent iExitStatus, sMessage
49+
50+
Wscript.Quit iReturn

0 commit comments

Comments
 (0)