执行脚本时隐藏Powershell窗口

时间:2019-08-05 05:04:07

标签: excel vba powershell

我是使用Powershell和脚本的新手。 在脚本文件中,有一些我想运行的简单命令,一切正常

Sub TestUDF()
MsgBox ScriptFile
End Sub

Function ScriptFile() As String
Dim wshShell        As Object
Dim wshShellExec    As Object
Dim strCommand      As String
Dim strOutput       As String

strCommand = "Powershell -File ""C:\Users\Future\Desktop\Test.ps1"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)
strOutput = wshShellExec.StdOut.ReadAll

ScriptFile = strOutput
End Function

我的问题是,运行代码时,powershell窗口会显示两秒钟。如何隐藏它以便根本不显示该窗口?

1 个答案:

答案 0 :(得分:3)

您将在命令上添加一个附加参数以调用PowerShell以保持窗口隐藏。将new Vue({ el:'#app', data:{ text: '', background: '#abf5c8' }, computed:{ textareaStyle: function(){ return this.background; } }, methods:{ changeBgColor: function(){ this.background='#71e3d8'; }, changeFirstBgColor: function(){ this.background='#abf5c8'; } } }) 调整为以下形式:

strCommand