早上好,
我正在尝试创建一个VBscript来自动化SAPGUI 中的一个函数
但我不确定如何让VBS读取与%USERID%相关的文本文件,然后循环脚本。
目前我有:
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
如果我输入一个%userID%,它就会起作用。
任何援助都将是伟大的。
p.s.总noob到VBS。-只有使用它,SAP GUI才能轻松地与它集成。
获取用户ID您可以使用WScript:
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
MsgBox objNetwork.UserName
或来自外壳:
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
或者来自环境变量(它应该工作,但当我测试时它是错误的!):
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment
MsgBox "USERNAME=" & WshEnv.Item("USERNAME")
请注意,所有这些都取决于所使用的操作系统。
您可以尝试以下操作:
'From the shell:
set wshell = createobject("Wscript.Shell")
Set WshEnv = Wshell.Environment("PROCESS")
session.findById("wnd[0]/usr/txtUSRID").text = wshEnv("USERID")
谨致问候,ScriptMan