2
votes

Good Morning Guys and Girls,

I'm trying to create a VBscript to automate a function in SAPGUI

But I Am unsure how to get the VBS to read the text file relace the %USERID% and then loop the script.

Currently I have :

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]/usr/radSYSCEN").select
session.findById("wnd[0]/usr/chkORG").selected = true
session.findById("wnd[0]/usr/txtUSRID").text = "%USERID%"
session.findById("wnd[0]/usr/chkORG").setFocus
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 3
session.findById("wnd[0]").sendVKey 3

Which will work If I put in a single %userID%.

Any Assistance would be great.

p.s. total noob to VBS. - Only using it SAP GUI integrates with it easily.

2
Use Scripting.FileSystemObject. But would having it from a command-line argument be better? - Dai

2 Answers

0
votes

to get the user ID You can use the WScript:

Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
MsgBox objNetwork.UserName

or from the shell:

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )

or from environment variable (it should work, but when i tested it was wrong!):

Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment
MsgBox "USERNAME=" & WshEnv.Item("USERNAME")

Note that all this depends on the OS used.

0
votes

You can try the following:

'From the shell:
set wshell = createobject("Wscript.Shell")
Set WshEnv = Wshell.Environment("PROCESS")
session.findById("wnd[0]/usr/txtUSRID").text = wshEnv("USERID")

Regards, ScriptMan