【问题标题】:SAP Front End Powershell scriptSAP 前端 Powershell 脚本
【发布时间】:2015-05-23 03:12:50
【问题描述】:

有人曾经在 SAP 前端使用过 powershell 吗?我正在尝试构建一个在 SAP GUI 7.30 中创建用户然后为用户分配角色的脚本。有没有人有任何我可以学习的阅读材料?我已经浏览了整个互联网,但找不到任何开始的地方。提前致谢!

【问题讨论】:

标签: powershell sap-gui


【解决方案1】:

您可以使用几个选项。

1) Stefan Schnell 为使用本机 PowerShell 的 SAP GUI 脚本创建了一个COM 连接器。你可以开始你的研究herehere。免责声明:我没有使用它,因为 Stefan 的网站目前已关闭,因此无法下载该组件。还有其他可用的选项。

2) Powershell + vbs:SAP GUI 7.30 具有所见即所得的功能,允许将用户操作脚本化到 .vbs 文件中。

因此,您可以在脚本录制开启时创建一个用户(这会输出带有脚本操作的 .vbs 文件),然后从 Powershell 启动此脚本。

c:\windows\system32\cscript.exe "C:\Users\xxxxxxxx\AppData\Roaming\SAP\SAP GUI\Scripts\CreateUserAndAssignRole.vbs"

如果您的 SAP 会话处于非活动状态,您首先需要启动 .exe 文件。那么您的 Powershell 部分将如下所示:

  #-Set the path to the SAP GUI directory-------------------------------
    $SAPGUIPath = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\"

  #-Set the SAP system ID-----------------------------------------------
    $SID = "Your system ID (a description/name from SAP Logon)"

  #-Set the instance number of the SAP system---------------------------
    $InstanceNo = "00"

  #-Start the SAP GUI---------------------------------------------------
    $SAPGUI = $SAPGUIPath + "sapgui.exe"
    & $SAPGUI $SID $InstanceNo

  #-Call the logon script---------------------------------
    c:\windows\system32\cscript.exe "C:\Users\xxxxxxx\AppData\Roaming\SAP\SAP GUI\Scripts\login.vbs" 

还有登录脚本:

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

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "yourMandant"
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "yourUsername"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "yourPass"
session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "yourLanguage"
session.findById("wnd[0]").sendVKey 0

不比 SAP 丑多少,不是吗?

3) 您可以在 .NET 中自动化 SAP GUI。一个工作示例是here

我个人在 C# 中完成了很多 (3),尽管它提供了许多有用的功能(尤其是日志记录和错误处理),但 c# 代码变得程序化并且非常繁琐。因此,我将我的解决方案迁移到 (2)。

脚本编写愉快!

康斯坦丁。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 2016-01-16
    • 2012-04-06
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多