お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"RE:IEとNCのproxy設定取得"

この発言は
#00905 KENCH さんのIEとNCのproxy設定取得
に対するコメントです

unit proxychk; interface uses SysUtils,Classes,Windows,Registry, HTSearch; //TEditorに付属のコンポーネント type TProxy = record HostName:string; Port:integer; ProxyOn:boolean; end; //関数定義*********************************** procedure FProxyGet(KBN:Char;var Proxy:TProxy); //コンスタント値定義 Const CProIE = 'I'; CProNC = 'N'; implementation function FCut(x:string;cutchar:char;p:integer):string; var i:integer; s:string; c:string; begin c:=cutchar; Result := ''; if p = 0 then exit; if c='' then exit; s:=x; while True do begin p:= p - 1; i:=AnsiPos(c,s); if p = 0 then begin if i > 0 then result := Copy(s,1,i -1) else result := s; break; end else if i = 0 then begin Result := ''; Break; end; s:=Copy(s,i + 1 ,Length(s)); end; end; procedure FProxyGet(KBN:Char;var Proxy:TProxy); var RegPath:string; Reg : TRegistry; i:integer; s,s2:string; buf:array[1..4] of char; Info: TSearchInfo; FSearchOptions: TSearchOptions; StrLst:TStringList; Const CIEHttp = 'http='; CIEProxyENabled = 'ProxyEnable'; CIEProxyServer = 'ProxyServer'; CIERegPath = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings\'; CNCRegPath = 'SOFTWARE\Netscape\Netscape Navigator\'; CNCVersion = 'CurrentVersion'; CNCUsers = 'Users'; CNCUserPath = 'DirRoot'; CNCCurrentUser = 'CurrentUser'; CNCInstall = 'Install Directory'; CNCProxyFileName = 'PREFS.JS'; CNCProxyEnabled = '"network.proxy.type",'; CNCProxyServer = 'network.proxy.http", "'; CNCProxyPort = 'network.proxy.http_port",'; begin Case KBN of CProIE:begin Reg := TRegistry.create; RegPath:=CIERegPath; Try Reg.RootKey := HKEY_CURRENT_USER; Reg.OpenKey(REGPATH, true); if Reg.ValueExists(CIEProxyEnabled) = false then begin Proxy.ProxyOn := false; end else begin try Reg.ReadBinaryData(CIEProxyEnabled,buf,4); except //IE5では数字になった(本当はBoolean?) on E: ERegistryException do begin i:=Reg.ReadInteger(CIEProxyEnabled); if i = 1 then buf[1] := chr(1) else buf[1] := chr(0); end; end; //Proxy設定 if buf[1] = Chr(1) then begin Proxy.ProxyOn := True; s:= Reg.ReadString(CIEProxyServer); //全て同じ? info.Start := 0; info.Length :=0; s2:=CIEHttp; FSearchOptions := [sfrDown]; if SearchText(PChar(s),info,s2,FSearchOptions) = True then begin //ホスト&Port i:=info.start + info.length + 1; s2:=':'; if SearchText(PChar(s),info,s2,FSearchOptions) = True then begin Proxy.HostName := Copy(s,i,info.start - i + 1); i:=info.start + info.length; s2:=';'; if SearchText(PChar(s),info,s2,FSearchOptions) = True then begin if trim(copy(s,i+1,info.start - i)) = '' then Proxy.Port := 80 else Proxy.port := strtoint(copy(s,i+1,info.start - i)); end else begin if Trim(Copy(s,i+1,length(s))) = '' then Proxy.Port := 80 else Proxy.Port := strtoint(Copy(s,i+1,length(s))); end; end else begin Proxy.ProxyOn := false; end; end else begin //ホスト Proxy.HostName:=FCut(s,':',1); //Port if Trim(FCut(s,':',2)) = '' then Proxy.Port := 80 else Proxy.Port:=strtoint(FCut(s,':',2)); end; end else begin Proxy.ProxyOn := false; end; end; Reg.CloseKey; Finally Reg.Free; End; end; CProNC:begin //カレントユーザ取得 Reg := TRegistry.create; StrLst:=TStringList.create; Try Reg.RootKey := HKEY_LOCAL_MACHINE; RegPath:=CNCRegPath + CNCUsers; Reg.OpenKey(RegPath, true); if Reg.ValueExists(CNCCurrentUser) = false then begin //ユーザデータ見つからない場合にはインストールディレクトリ //バージョン情報を取得する Reg.CLoseKey; RegPath:=CNCRegPath; Reg.OpenKey(RegPath,true); if Reg.ValueExists(CNCVersion) = false then begin Proxy.ProxyOn := false; Reg.CloseKey; exit; end else begin s2:=Reg.ReadString(CNCVersion); Reg.CloseKey; RegPath := CNCRegPath + s2 + '\Main'; Reg.OpenKey(RegPath,true); if Reg.ValueExists(CNCInstall) = false then begin Proxy.ProxyOn := false; Reg.CloseKey; exit; end else begin //デフォルトのユーザパスを取得 s2 := Reg.ReadString(CNCInstall); s:=ExtractFilePath(s2) + CNCUsers + '\Default'; Proxy.ProxyOn := True; end; end; end else begin //ユーザデータがある場合のユーザデータ格納エリア s:= Reg.ReadString(CNCCurrentUser); Reg.CloseKey; RegPath:=CNCRegPath + CNCUsers + '\' + s + '\'; Reg.OpenKey(RegPath,true); if Reg.ValueExists(CNCUserPath) = false then begin proxy.ProxyOn := false; Reg.CloseKey; exit; end else begin s:= Reg.ReadString(CNCUserPath); Proxy.ProxyOn := True; end; end; Reg.CloseKey; //ユーザデータ格納エリア取得 s:=s+'\'+CNCProxyFileName; //プロファイル存在チェック if FileExists(s) = true then begin //プロファイル読み込み StrLst.LoadFromFile(s); //Proxy設定 info.Start := 0; info.Length :=0; s2:=CNCProxyEnabled; FSearchOptions := [sfrDown]; if SearchText(PChar(StrLst.Text),info,s2,FSearchOptions) = True then begin i:=info.Start + info.Length; s2:=')'; if SearchText(PChar(StrLst.Text),info,s2,FSearchOptions) = True then begin s:=trim(Copy(StrLst.Text,i+1,info.start - i)); if s='' then begin Proxy.ProxyOn := false; exit; end else begin Case s[1] of '1':begin //ホスト********************// info.Start := 0; info.Length :=0; s2:=CNCProxyServer; if SearchText(PChar(StrLst.text),info,s2, FSearchOptions) = True then begin i:=info.start + info.length; s2:='"'; if SearchText(PChar( StrLst.text),info,s2,FSearchOptions) = True then begin Proxy.HostName:= trim(Copy(StrLst.Text,i+1, Info.start - i)); //Port info.Start := 0; info.Length :=0; s2:=CNCProxyPort; if SearchText(PChar(StrLst.text), info,s2,FSearchOptions) = True then begin i:=info.start + info.length; s2:=')'; if SearchText( PChar(StrLst.text), info,s2,FSearchOptions) = True then begin s:=Trim(Copy(StrLst.Text, i+1,Info.Start - i)); if s = '' then Proxy.Port := 80 else Proxy.Port := strtoint(s); end else begin Proxy.Port := 80; end; end else begin Proxy.Port := 80; end; end else begin proxy.ProxyOn := false; end; end else begin Proxy.ProxyOn := false; end; end; else Proxy.ProxyOn := false; end; end; end; end; end; Finally StrLst.free; Reg.Free; End; end; end; end; end. Original document by KENCH 氏 ID:(GDH01352)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum