Hi,
Habe etwas für dich gecoded
Damit kannst du im IE automatisch in den
"Depot-Manager" einloggen, falls die seite 'LoginBody' offen ist.
Dieser Code lässt sich rel. einfach auf einen TWebbrowser umschreiben
oder an deine Bedürfnisse anpassen.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121:
| uses MSHTML_TLB, ShellAPI;
function ExecuteScript(doc: IHTMLDocument2; script: string; language: string): Boolean; var win: IHTMLWindow2; Olelanguage: Olevariant; begin if doc <> nil then begin try win := doc.parentWindow; if win <> nil then begin try Olelanguage := language; win.ExecScript(script, Olelanguage); finally win := nil; end; end; finally doc := nil; end; end; end;
function LoginIE(Zugangsnummer, PIN, Identifier: string; ATitle : string = ''): Boolean; type TIEFields = record tagName : String; fType : String; Name : String; end; const MaxIEFields = 3; IEFields: array[1..MaxIEFields] of TIEFields = ( (tagName : 'INPUT'; fType : 'text'; Name: 'authentificationnumberLogin'), (tagName : 'INPUT'; fType : 'password'; Name: 'pinLogin'), (tagName : 'INPUT'; fType : 'password'; Name: 'identifierLogin') ); var ShellWindow: IShellWindows; WB: IWebbrowser2; spDisp: IDispatch; IDoc1: IHTMLDocument2; Document: Variant; k, m, o: Integer; ovElements: OleVariant; i: Integer; IEFieldsCounter: Integer; IEFormName : array[1..MaxIEFields] Of String; begin Result := Boolean(0); ShellWindow := CoShellWindows.Create; for k := 0 to ShellWindow.Count do begin spDisp := ShellWindow.Item(k); if spDisp = nil then Continue; spDisp.QueryInterface(iWebBrowser2, WB); IEFieldsCounter := 0; if WB <> nil then begin WB.Document.QueryInterface(IHTMLDocument2, iDoc1); if iDoc1 <> nil then begin WB := ShellWindow.Item(k) as IWebbrowser2; Document := WB.Document; if (Pos(ATitle, Document.Title) <> 0) or (ATitle = '') then for m := 0 to Document.forms.Length - 1 do begin ovElements := Document.forms.Item(m).elements; for i := ovElements.Length - 1 downto 0 do begin try Form1.mmoMemo1.Lines.Add(ovElements.item(i).name); for o := 1 to 3 do if (ovElements.item(i).tagName = IEFields[o].tagName) and (ovElements.item(i).type = IEFields[o].fType) and (ovElements.item(i).name = IEFields[o].Name) then begin case o of 1: ovElements.item(i).Value := Zugangsnummer; 2: ovElements.item(i).Value := PIN; 3: ovElements.item(i).Value := Identifier; end; IEFormName[o] := Document.forms.Item(m).name; If (IEFormName[o] = '') then IEFormName[o] := 'forms[' + IntToStr(m) + ']'; inc(IEFieldsCounter); end; except end; end; end; end; end; if (IEFieldsCounter = MaxIEFields) and (IEFormName[1] = IEFormName[2]) then begin ExecuteScript(iDoc1, 'document.' + IEFormName[1] + '.submit()', 'JavaScript'); Result := Boolean(1); end; end; end;
procedure TForm1.btnButton1Click(Sender: TObject); begin LoginIE('Zugangsnummer', 'PIN','Identifier','LoginBody'); end; |