Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Sub SAPGUI_New()
  2.  
  3. Dim OpenNewConnFlag
  4.  
  5. Dim Application, SAPGUI, Connection, SapGuiAuto, WScript, Session, wshShell, oExec
  6.  
  7. OpenNewConnFlag = False
  8.  
  9.  
  10. If Not IsObject(Application) Then
  11. On Error Resume Next
  12. 'If the script can't get the object, it starts saplogon
  13. 'and try to get the object again.
  14. Set SapGuiAuto = GetObject("SAPGUI")
  15. If Err.Number <> 0 Then
  16. On Error GoTo 0
  17. Set wshShell = CreateObject("WScript.Shell")
  18. Set oExec = wshShell.Exec("c:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")
  19. On Error GoTo 0
  20. Do While Not wshShell.AppActivate("SAP Logon 730")
  21. 'WScript.Sleep 500
  22. Loop
  23. Set SapGuiAuto = GetObject("SAPGUI")
  24. Else
  25. On Error GoTo 0
  26. End If
  27. Set Application = SapGuiAuto.getScriptingEngine
  28. End If
  29.  
  30. If Not IsObject(Connection) Then
  31. On Error Resume Next
  32. 'If the script can't open connection 0, it opens a
  33. 'new connection
  34. Set Connection = Application.OpenConnection("G4P GCF/Cons Prod", True)
  35. If Err.Number <> 0 Then
  36. On Error GoTo 0
  37. Application.OpenConnectionByConnectionString _
  38. "/H/10.100.200.100/S/3200", True
  39. OpenNewConnFlag = True
  40. Else
  41. On Error GoTo 0
  42. OpenNewConnFlag = True
  43. End If
  44. 'Set Connection = Application.OpenConnection("G4P GCF/Cons Prod", True)
  45. End If
  46.  
  47. If Not IsObject(Session) Then
  48. Set Session = Connection.Children(0)
  49. 'If the script opens a new connection, it logon to the system
  50. If OpenNewConnFlag = True Then
  51. With Session
  52.  
  53. Dim user
  54. Dim pass
  55.  
  56. username = username.Text
  57. pass = password.Text
  58.  
  59. .findById("wnd[0]/usr/txtRSYST-BNAME").Text = username
  60. .findById("wnd[0]/usr/pwdRSYST-BCODE").Text = pass
  61. .findById("wnd[0]").sendVKey 0
  62. '======
  63. On Error Resume Next
  64. .findById("wnd[1]/usr/radMULTI_LOGON_OPT1").Select
  65. If Err.Number <> 0 Then
  66. On Error GoTo 0
  67. Else
  68. .findById("wnd[1]/usr/radMULTI_LOGON_OPT1").SetFocus
  69. .findById("wnd[1]/tbar[0]/btn[0]").press
  70. End If
  71. End With
  72. End If
  73. End If
  74. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement