summaryrefslogtreecommitdiff
path: root/env/wsl/run_hidden.vbs
blob: b891159867e28bb50d6e0424c6e140b14a737f17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
' https://stackoverflow.com/a/41229169
' Simple command-line help.
select case WScript.Arguments(0)
case "-?", "/?", "-h", "--help"
  WScript.echo "Usage: runHidden executable [...]" & vbNewLine & vbNewLine & "Runs the specified command hidden (without a visible window)."
  WScript.Quit(0)
end select

' Separate the arguments into the executable name
' and a single string containing all arguments.
exe = WScript.Arguments(0)
sep = ""
for i = 1 to WScript.Arguments.Count -1
  ' Enclose arguments in "..." to preserve their original partitioning, if necessary.
  if Instr(WScript.Arguments(i), " ") > 0 then
    args = args & sep & """" & WScript.Arguments(i) & """"
  else
    args = args & sep & WScript.Arguments(i)
  end if
  sep = " "
next

' Execute the command with its window *hidden* (0)
WScript.CreateObject("Shell.Application").ShellExecute exe, args, "", "open", 0