I'm trying to write a VBScript that opens a SAP session, with Single-Sign On capability.
I've already found some information about this topic, or similar ones, here and on other sites, but none of them suit my requirement..
This is what I have so far, taken from a SAP Discussion Forum:
But an error happens in the SAP GUI;
Hostame 'PRD' unknown
Line: 896
Method: NiPGetHostByName: 'PRD' not found
Can anybody help me?
Option Explicit
Dim WSHShell, SAPGUIPath, SID, InstanceNo, WinTitle
Set WSHShell = WScript.CreateObject("WScript.Shell")
If IsObject(WSHShell) Then
SAPGUIPath = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\"
SID = "PRD"
InstanceNo = "00"
WSHShell.Exec SAPGUIPath & "sapgui.exe " & SID & " " & _
InstanceNo
WinTitle = "SAP"
While Not WSHShell.AppActivate(WinTitle)
WScript.Sleep 250
Wend
Set WSHShell = Nothing
End If
Full disclosure, I don't use SAP so anything I say is purely educated guess work.
After looking at the question for a little while, I may have a suggestion.
The error is coming directly from the SAP GUI and is quite detailed, which allows us to make some assumptions;
Let's try breaking down the error. With this particular error we are blessed with a wealth of information (will pick out some key ones);
Armed with all this information, two things become apparent;
NiPGetHostByName
which suggests the SAP GUI is expecting to locate the Host using the Name.PRD
value appears to be the SID column not the Name.So, should you possibly be passing the Name instead of the SID as it appears the SAP GUI is not working from the SID and wrongly assumes PRD
is the Name and hence doesn't find it?
I would suggest trying something like;
Option Explicit
Dim WSHShell, SAPGUIPath, SID, InstanceNo, WinTitle, Name
Set WSHShell = WScript.CreateObject("WScript.Shell")
If IsObject(WSHShell) Then
SAPGUIPath = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\"
Name = """1. SAP ECC Production (PRD)"""
SID = "PRD"
InstanceNo = "00"
WSHShell.Exec SAPGUIPath & "sapgui.exe " & Name & " " & _
InstanceNo
WinTitle = "SAP"
While Not WSHShell.AppActivate(WinTitle)
WScript.Sleep 250
Wend
Set WSHShell = Nothing
End If