excel - 执行脚本时隐藏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窗口出现两秒钟。如何隐藏它以便根本不显示此窗口?
解决方案
您将在命令中添加一个附加参数来调用 PowerShell 以保持窗口隐藏。调整strCommand
到这样的东西:
strCommand = "Powershell -WindowStyle Hidden -File ""C:\Users\Future\Desktop\Test.ps1"""
推荐阅读
- android - Android Room - 使用 LiveData 进行 SELECT 查询
- android - 内部类 ViewHolder 的构造函数只能被包含类的接收者调用
- r - 在汇总 R 中声明更改变量名称?
- wix - 安装时删除其他软件
- spark-structured-streaming - 如何在 Azure Databricks 中使用 EventHubsForeachWriter
- html - 路由导致返回原始页面
- excel - Sumif 函数动态
- laravel - 带有模型函数的 laravel 查询
- php - Webhook:file_get_contents 为空
- azure - Azure AD OpenID 连接 - 组未显示在令牌中