我如何 运行 VBScript 文件在后台静默运行?

How can I run a VBScript file silently in the background?

我想 运行 一个 VBScript 文件,因为它只是隐藏脚本的一部分。

我正在使用 VBScript 从 SAP 中自动导出文档,工作正常,除非在 SAP-GUI 中显示每个步骤。

VBScript 文件是在 PowerShell 中启动的,我已经在其中尝试隐藏进程,例如:

$vbsPDPPath = "$env:userprofile\AppData\Roaming\KPIReport"  
$vbsPDPName = "SAP-ExportPDP.vbs"
$processNamePDP = $vbsPDPPath + "\" + $vbsPDPName
Start-Process $processNamePDP -WindowStyle Hidden

虽然没有成功。

我正在寻找类似 VBA 的解决方案,您可以在其中添加:

Application.ScreenUpdating = False

还是不知道怎么解决。我认为让您查看 vbs 代码会有所帮助,一定有问题。

我注意到我没有提到隐藏 SAP GUI 以及 Excel 应用程序。

Dim Number_PDP
Dim testNode
Dim WshShell
Dim profile

Set WshShell = WScript.CreateObject("WScript.Shell")
profile = WshShell.ExpandEnvironmentStrings("%USERPROFILE%")

'read XML file

Set xmlDoc = CreateObject("MSXML.DomDocument")
xmlDoc.Load profile & "\AppData\Roaming\KPIReport\DIS.xml" 

For Each testNode In xmlDoc.selectNodes("/Reports/Report")

   Number_PDP = testNode.SelectSingleNode("DIS_PDP").Text

               'connect to SAP GUI

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

SapGuiAuto.Visible = false 
              'not working, thought it is possible to hide SAP

session.findById("wnd[0]").resizeWorkingPane 132,31,false
session.findById("wnd[0]/tbar[0]/okcd").text = "/n cv04n"
session.findById("wnd[0]").sendVKey 0
...
              'cutted a couple of rows, just opens a document in Excel with SAP


              'after SAP opens Excel I used this code to save the documents 
set objExcel = getobject(,"Excel.Application")

if err.number<>0 then
    err.clear
end if
              'this part should be hidden as well, not working
objExcel.Visible = false     
objExcel.ActiveWorkbook.SaveAs profile & "\AppData\Roaming\KPIReport\" & Number_PDP
objExcel.ActiveWorkbook.Close
objExcel.Quit

Next

我会在这两种情况下使用变通方法。

例如:

. . .
'session.findById("wnd[0]").resizeWorkingPane 132,31,false
session.findById("wnd[0]").iconify
. . .

. . .
'objExcel.Visible = false     
objExcel.WindowState = 2
. . .

此致, 脚本人