SAP Jobsuche bei DV-Treff


Suchen
Lutz Fricke
vor 8 Jahre
Es funktioniert nicht!

Ich habe heute früh nochmal etwas rumprobiert.

Dazu noch eine blöde Frage: Hast Du SAP_Apllication mit Absicht so geschrieben? Ich hab's in SAP_Application geändert gehabt.

Ich bekomme in der Schleife als Error-Nummer die 424 angegeben.

Scheinbar stört er sich am Logon-Pad. Der Start bei geschlossenem SAP funktioniert, sobald aber das Logon-Pad geöffnet ist, funktioniert's nicht mehr.

Gruß,

Lutz

ScriptMan
vor 8 Jahre
Es gibt keine blöden Fragen sondern nur dumme Antworten!👍

Selbstverständlich heißt es richtig SAP_Application.

Anscheinend gibt es aber neuerdings einen Unterschied, ob nur das Logon-Pad aktiv ist oder ob SAP tatsächlich aktiv ist. Beides wird hoffentlich auch bei Dir unter Windows 8.1 als aktiver Prozess = saplogon.exe erkennbar. Und das kann man sich zunutze machen:

'***** 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

If Not IsObject(SAP_Application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set SAP_Application = SapGuiAuto.GetScriptingEngine

End If

error = Err.Number

On Error GoTo 0

Anzahl = 0

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 error <> 0 Then

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 SAP_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

Grüße,

ScriptMan

Lutz Fricke
vor 8 Jahre
Jetzt funktioniert's auch mit Logon-Pad 😁 .

Aber es wird auch eine SAP-Session gestartet wenn bereits eine läuft 😞 .

Hab schon etwas rumprobiert, aber find's nicht.

ScriptMan
vor 8 Jahre
Gut Ding braucht Weile!

Um tatsächlich einen letzten Tipp abzugeben, müsstest Du was selbst ausprobieren. Während einer aktiven SAP-Session müsste man folgendes Skript starten und sehen was es macht:

If Not IsObject(SAP_Application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set SAP_Application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(SAP_Connection) Then

Set SAP_Connection = SAP_Application.Children(0)

End If

If Not IsObject(session) Then

Set session = SAP_Connection.Children(0)

End If

msgbox "Der aktuelle Modus lautet: " & session.info.sessionnumber

Grüße,

ScriptMan

Lutz Fricke
vor 8 Jahre
Der aktuelle Modus lautet: 1
ScriptMan
vor 8 Jahre
Mein letzter Tipp:

'***** 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

If Not IsObject(SAP_Application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set SAP_Application = SapGuiAuto.GetScriptingEngine

End If

error = Err.Number

On Error GoTo 0

Anzahl = 0

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 error <> 0 Then

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

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 error <> 0 then

if Number_Session = 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

Lutz Fricke
vor 8 Jahre
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

ScriptMan
vor 8 Jahre
Hallo Lutz,

na, wer sagt es denn...? Jetzt hast Du endlich eine lauffähige Version für Windows 8.1 !

Und alle anderen, die mitgelesen haben, selbstverständlich auch. Aber das ist Sinn und Zweck von solchen Foren, wo man versucht, nicht nur das "Wissen" zu finden sondern u.U. auch weiter zu geben und zu teilen.

Grüße,

ScriptMan

Lutz Fricke
vor 8 Jahre
Hallo ScriptMan,

jetzt hab ich da doch noch nen Problem gefunden 😢 .

Sobald das Script bei gesperrtem Bildschirm startet, läuft es im Block

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

bei

Set SAP_Connection = SAP_Application.openconnection(myConnection)

in den Fehler "Objekt erforderlich: 'SAP_Application'".

Das passiert ganz egal in welchem Zustand SAP sich befindet.

Gruß,

Lutz