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

时间:2017-01-12 11:05:35

标签: powershell vbscript sap

我想以静默方式运行VBScript文件,因为它只是隐藏脚本的一部分。

除非显示SAP-GUI中的每个步骤,否则我正在使用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

1 个答案:

答案 0 :(得分:0)

我会在两种情况下都使用解决方法。

例如:

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

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

此致 ScriptMan