赞
踩
录制 vbs
1.事务代码:RZ11
2.输入参数名称:sapgui/user_scripting
3.最后一个项目 = true
4.登陆器的 option
5.scripting 打勾
6.copy下面代码
'------------------------------------------------------------------
'- VBScript to start SAP Logon if process doesn't exists and connect
'- to an SAP system. The SAP Logon process is detected via WMI
'- (Windows Management Instrumentarium), also the termination.
'-----------------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Variables-----------------------------------------------------------
Dim SAPLogon, SAPLogonTitle
SAPLogon = "saplogon.exe" : SAPLogonTitle = "SAP Logon 770"
'SAPLogon = "saplgpad.exe" : SAPLogonTitle = "SAP Logon Pad 740"
Dim SysDescr, SysIP
'-----------------------------------------------------------------
'Sysdescr系?描述,SysIP?接地址.??一.使用ip的?候如果用用router,
'需要将router加在地址前?.用/H/?始
'-----------------------------------------------------------------
'SysDescr = "xxxdev"
SysIP = "/H/XXX.X.XX.XX"
' SysIP = "/H/HY.XX.NET/H/XXX.XXX.XX.XX"
'-Function FindProcess------------------------------------------------
Function FindProcess(ProcessName)
'-Variables-------------------------------------------------------
Dim WMIServ, Processes, Process
FindProcess = False
Set WMIServ = GetObject("winmgmts:{impersonationLevel=" & _
"impersonate}!\\.\root\cimv2")
Set Processes = WMIServ.ExecQuery("Select * from Win32_Process " & _
"Where Name = '" & ProcessName & "'")
For Each Process In Processes
FindProcess = True
Exit Function
Next
End Function
'-Sub TerminateProcess------------------------------------------------
Sub TerminateProcess(ProcessName)
'-Variables-------------------------------------------------------
Dim WMIServ, Processes, Process
Set WMIServ = GetObject("winmgmts:{impersonationLevel=" & _
"impersonate}!\\.\root\cimv2")
Set Processes = WMIServ.ExecQuery("Select * from Win32_Process " & _
"Where Name = '" & ProcessName & "'")
For Each Process In Processes
Process.Terminate()
Exit Sub
Next
End Sub
'-Function GetSAPGUIObject--------------------------------------------
'- This function starts the SAP Logon if it is necessary and delivers
'- its object
'---------------------------------------------------------------------
Function GetSAPGUIObject()
'-Variables-------------------------------------------------------
Dim WshShell, Exec
If FindProcess(SAPLogon) Then
Set GetSAPGUIObject = GetObject("SAPGUI")
Else
Set WshShell = CreateObject("WScript.Shell")
Set Exec = WshShell.Exec(_
"c:\Program Files (x86)\SAP\FrontEnd\SAPgui\" & SAPLogon)
Do While Not WshShell.AppActivate(SAPLogonTitle)
WScript.Sleep 500
Loop
Set GetSAPGUIObject = GetObject("SAPGUI")
End If
End Function
'-Sub Main------------------------------------------------------------
Sub Main()
'-Variables-------------------------------------------------------
Dim SapGuiAuto, Application, Connection, Session
Set SapGuiAuto = GetSAPGUIObject()
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
Set Application = SapGuiAuto.GetScriptingEngine
If Not IsObject(Application) Then
Set SapGuiAuto = Nothing
Exit Sub
End If
'-----------------------------------------------------------------
'- 在下?决定用系?描述或者ip地址
'-----------------------------------------------------------------
'Set Connection = Application.OpenConnection(SysDescr, True)
Set Connection = Application.OpenConnectionByConnectionString( SysIP, True)
If Not IsObject(Connection) Then
Set Application = Nothing
Set SapGuiAuto = Nothing
Exit Sub
End If
Set Session = Connection.Children(0)
If Not IsObject(Session) Then
Set Connection = Nothing
Set Application = Nothing
Set SapGuiAuto = Nothing
Exit Sub
End If
MyScript(Session)
'Set Session = Nothing
'Set Connection = Nothing
'Set Application = Nothing
'Set SapGuiAuto = Nothing
'TerminateProcess SAPLogon
End Sub
'-Sub MyScript--------------------------------------------------------
Sub MyScript(Session)
'-----------------------------------------------------------------
'- 在下?更改用?,密?,?言client.
'-----------------------------------------------------------------
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "XXX"
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "XXX"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "XXXXXXXXX"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "JA"
session.findById("wnd[0]").sendVKey 0
End Sub
'-Main----------------------------------------------------------------
Main
7.后缀位 vbs
8.执行时注意 弹出的框 不按回车,点鼠标为好。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。