Hallo ScriptMan,
hab mir jetzt gedacht, warum die ganze Prozedur durchlaufen, wenn SAP eh schon angemeldet ist😕 .
Mein Ergebnis schaut wie folgt aus und scheint zu funktionieren:
'***** Parameter für SAP - Anmeldung *****
PFAD = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"
myConnection = "RP1 – SSO – ECC Production"
'******
'***** Auto-Start *****
set wshell = createObject("Wscript.Shell")
on error resume next
 Number_Session = 0
 Set SapGuiAuto = GetObject("SAPGUI")
 Set SAP_Application = SapGuiAuto.GetScriptingEngine
 Set SAP_Connection = SAP_Application.Children(0)
 Set session = SAP_Connection.Children(0)
 Number_Session = session.info.sessionnumber
on error goto 0 
if Number_Session = 0 then
	Number_Process = 0
	Dim objWMIService, colItems, objItem, strComputer
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set colItems = objWMIService.InstancesOf("Win32_Process")
	For Each objItem In colItems
 		'WScript.Echo objItem.ProcessId & ":" & objItem.Name
 		if right(objItem.Name,12)="saplogon.exe" then Number_Process = Number_Process + 1
	Next
	Set objWMIService = Nothing
	Set colItems = Nothing
	If Number_Process = 0 Then
 		do
 			wshell.run chr(34) & PFAD & chr(34)
			wscript.sleep 4000 
			error = 0
			On Error Resume Next
			If Not IsObject(SAP_Application) Then
				Set SapGuiAuto = GetObject("SAPGUI") 
				Set SAP_Application = SapGuiAuto.GetScriptingEngine
			End If
			error = Err.Number
			if error = 0 then exit do
			Anzahl = Anzahl + 1
			if Anzahl = 5 then exit do 
			On Error GoTo 0
 		loop
		If error <> 0 Then
			MsgBox "SAP Logon ist nicht installiert." , vbInformation
		end if
	end if
on error resume next
If Not IsObject(SAP_connection) Then
	Set connection = SAP_Application.Children(0)
	error = err.number
	msgbox error
End If
If Not IsObject(session) Then
	Set session = SAP_connection.Children(0)
	error = err.number
	msgbox error
End If
on error goto 0 
if error <> 0 then
	Set SAP_Connection = SAP_Application.openconnection(myConnection)
	Set session = SAP_Connection.Children(0)
	session.findById("wnd[0]").maximize
	session.findById("wnd[0]").sendVKey 0
	wscript.sleep 2000
else
'	msgbox "Sie sind bereits im SAP angemeldet.", vbinformation, "SAP - Anmeldung"
end if
end if
Magst Du mal checken, ob irgendetwas zu viel drinsteht.
Gruß,
Lutz