Экспертная система Delphi.int.ru

Сообщество программистов
Общение, помощь, обмен опытом

Логин:
Пароль:
Регистрация | Забыли пароль?

Delphi.int.ru Expert

Другие разделы портала

Переход к вопросу:

#   

Статистика за сегодня:  


Лучшие эксперты

Подробнее »



Вопрос # 1 389

/ вопрос открыт /

Здравствуйте, эксперты!
Не подскажите как получить значения настроек соединения (прокси порт, прокси адресс), которые используются в Internet Explorer или другом броузере по умолчанию.
Заранее благодарен.

ss Вопрос ожидает решения (принимаются ответы, доступен мини-форум)

Вопрос задал: ss (статус: Посетитель)
Вопрос отправлен: 3 марта 2008, 12:50
Состояние вопроса: открыт, ответов: 1.

Ответ #1. Отвечает эксперт: Feniks

Здравствуйте, ss!
Держите в Приложении несколько примеров.
Желаю удачи.

Приложение:
  1.  
  2.  
  3.  
  4.  
  5. {
  6. First we create a temporary file and call the
  7. function FindExecutable to get the associated Application.
  8. }
  9.  
  10.  
  11. function GetAppName(Doc: string): string;
  12. var
  13. FN, DN, RES: array[0..255] of char;
  14. begin
  15. StrPCopy(FN, DOC);
  16. DN[0] := #0;
  17. RES[0] := #0;
  18. FindExecutable(FN, DN, RES);
  19. Result := StrPas(RES);
  20. end;
  21.  
  22. function GetTempFile(const Extension: string): string;
  23. var
  24. Buffer: array[0..MAX_PATH] of char;
  25. aFile: string;
  26. begin
  27. GetTempPath(SizeOf(Buffer) - 1, Buffer);
  28. GetTempFileName(Buffer, 'TMP', 0, Buffer);
  29. SetString(aFile, Buffer, StrLen(Buffer));
  30. Result := ChangeFileExt(aFile, Extension);
  31. end;
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. var
  35. f: System.Text;
  36. temp: string;
  37. begin
  38. // get a unique temporary file name
  39. // eine eindeutige Temporare Datei bekommen
  40. temp := GetTempFile('.htm');
  41. // Create the file
  42. // Datei erstellen
  43. AssignFile(f, temp);
  44. rewrite(f);
  45. closefile(f);
  46. // Show the path to the browser
  47. // Pfad + Programmname zum Browser anzeigen.
  48. ShowMessage(GetAppName(temp));
  49. // Finally delete the temporary file
  50. // Temporaare Datei wieder loschen
  51. Erase(f);
  52. end;
  53.  
  54.  
  55. //Using the Registry:
  56. //************************************************
  57.  
  58. uses
  59. Registry;
  60.  
  61. procedure TForm1.Button1Click(Sender: TObject);
  62. var
  63. Reg: TRegistry;
  64. KeyName: string;
  65. ValueStr: string;
  66. begin
  67. Reg := TRegistry.Create;
  68. try
  69. Reg.RootKey := HKEY_CLASSES_ROOT;
  70. KeyName := 'htmlfileshellopencommand';
  71. if Reg.OpenKey(KeyName, False) then
  72. begin
  73. ValueStr := Reg.ReadString('');
  74. Reg.CloseKey;
  75. ShowMessage(ValueStr);
  76. end
  77. else
  78.  
  79. finally
  80. Reg.Free;
  81. end;
  82. end;
  83.  
  84.  
  85. //************************************************
  86. {Copyright (c) by Code Central}
  87.  
  88. type
  89. TBrowserInformation = record
  90. Name: string;
  91. Path: string;
  92. Version: string;
  93. end;
  94.  
  95. function LongPathName(ShortPathName: string): string;
  96. var
  97. PIDL: PItemIDList;
  98. Desktop: IShellFolder;
  99. WidePathName: WideString;
  100. AnsiPathName: AnsiString;
  101. begin
  102. Result := ShortPathName;
  103. if Succeeded(SHGetDesktopFolder(Desktop)) then
  104. begin
  105. WidePathName := ShortPathName;
  106. if Succeeded(Desktop.ParseDisplayName(0, nil, PWideChar(WidePathName),
  107. ULONG(nil^), PIDL, ULONG(nil^))) then
  108.  
  109. try
  110. SetLength(AnsiPathName, MAX_PATH);
  111. SHGetPathFromIDList(PIDL, PChar(AnsiPathName));
  112. Result := PChar(AnsiPathName);
  113.  
  114. finally
  115. CoTaskMemFree(PIDL);
  116. end;
  117. end;
  118. end;
  119.  
  120. function GetDefaultBrowser: TBrowserInformation;
  121. var
  122. tmp: PChar;
  123. res: LPTSTR;
  124. Version: Pointer;
  125. VersionInformation: Pointer;
  126. VersionInformationSize: Integer;
  127. Dummy: DWORD;
  128. begin
  129. tmp := StrAlloc(255);
  130. res := StrAlloc(255);
  131. Version := nil;
  132. try
  133. GetTempPath(255, tmp);
  134. if FileCreate(tmp + 'htmpl.htm') <> -1 then
  135. begin
  136. if FindExecutable('htmpl.htm', tmp, res) > 32 then
  137. begin
  138. Result.Name := ExtractFileName(res);
  139. Result.Path := LongPathName(ExtractFilePath(res));
  140. // Try to determine the Browser Version
  141. VersionInformationSize := GetFileVersionInfoSize(Res, Dummy);
  142. if VersionInformationSize > 0 then
  143. begin
  144. GetMem(VersionInformation, VersionInformationSize);
  145. GetFileVersionInfo(Res, 0, VersionInformationSize, VersionInformation);
  146. VerQueryValue(VersionInformation, ('StringFileInfo040904E4ProductVersion'),
  147. Pointer(Version), Dummy);
  148. if Version <> nil then
  149. Result.Version := PChar(Version);
  150. FreeMem(VersionInformation);
  151. end;
  152. end
  153. else
  154. ShowMessage('Cannot determine the executable.');
  155. SysUtils.DeleteFile(tmp + 'htmpl.htm');
  156. end
  157. else
  158. ShowMessage('Cannot create temporary file.');
  159. finally
  160. StrDispose(tmp);
  161. StrDispose(res);
  162. end;
  163. end;
  164. ==================================
  165.  
  166. uses
  167. WinInet;
  168.  
  169. function GetProxyInformation: string;
  170. var
  171. ProxyInfo: PInternetProxyInfo;
  172. Len: LongWord;
  173. begin
  174. Result := '';
  175. Len := 4096;
  176. GetMem(ProxyInfo, Len);
  177. try
  178. if InternetQueryOption(nil, INTERNET_OPTION_PROXY, ProxyInfo, Len) then
  179. if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY then
  180. begin
  181. Result := ProxyInfo^.lpszProxy
  182. end;
  183. finally
  184. FreeMem(ProxyInfo);
  185. end;
  186. end;
  187.  
  188. {**************************************************************************
  189. * NAME: GetProxyServer
  190. * DESC: Proxy-Server Einstellungen abfragen
  191. * PARAMS: protocol => z.B. 'http' oder 'ftp'
  192. * RESULT: [-]
  193. * CREATED: 08-04-2004/shmia
  194. *************************************************************************}
  195. procedure GetProxyServer(protocol: string; var ProxyServer: string;
  196. var ProxyPort: Integer);
  197. var
  198. i: Integer;
  199. proxyinfo, ps: string;
  200. begin
  201. ProxyServer := '';
  202. ProxyPort := 0;
  203.  
  204. proxyinfo := GetProxyInformation;
  205. if proxyinfo = '' then
  206. Exit;
  207.  
  208. protocol := protocol + '=';
  209.  
  210. i := Pos(protocol, proxyinfo);
  211. if i > 0 then
  212. begin
  213. Delete(proxyinfo, 1, i + Length(protocol));
  214. i := Pos(';', ProxyServer);
  215. if i > 0 then
  216. proxyinfo := Copy(proxyinfo, 1, i - 1);
  217. end;
  218.  
  219. i := Pos(':', proxyinfo);
  220. if i > 0 then
  221. begin
  222. ProxyPort := StrToIntDef(Copy(proxyinfo, i + 1, Length(proxyinfo) - i), 0);
  223. ProxyServer := Copy(proxyinfo, 1, i - 1)
  224. end
  225. end;
  226.  
  227. procedure TForm1.Button1Click(Sender: TObject);
  228. var
  229. ProxyServer: string;
  230. ProxyPort: Integer;
  231. begin
  232. GetProxyServer('http', ProxyServer, ProxyPort);
  233. Label1.Caption := ProxyServer;
  234. label2.Caption := IntToStr(ProxyPort);
  235. end;


Ответ отправил: Feniks (статус: Бакалавр)
Время отправки: 3 марта 2008, 13:16
Оценка за ответ: 5


Мини-форум вопроса

Мини-форум пуст.

Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.

Версия движка: 2.6+ (26.01.2011)
Текущее время: 22 февраля 2025, 11:43
Выполнено за 0.02 сек.