Recent

Author Topic: Start chrome Problem  (Read 3831 times)

whitehat

  • Jr. Member
  • **
  • Posts: 93
Start chrome Problem
« on: October 25, 2018, 02:54:56 pm »
i cant start the chrome when i execute my code there's a problem can any one check it

Code: Pascal  [Select][+][-]
  1. program pro;
  2. uses
  3.   crt,
  4.   Windows,
  5.   ShellApi;
  6.  
  7.  
  8.   procedure createdatabase;
  9. var
  10.   comand: AnsiString;
  11.   si: STARTUPINFOA;
  12.   pi: PROCESS_INFORMATION;
  13. begin
  14.   comand := 'start chrome localhost/a.html';
  15.  
  16.   ZeroMemory(@si, sizeof(si));
  17.   si.cb := sizeof(si);
  18.   si.dwFlags := STARTF_USESHOWWINDOW;
  19.   si.wShowWindow := SW_NORMAL;
  20.  
  21.   if CreateProcessA(nil, PAnsiChar(comand), nil, nil, False, 0, nil, nil, @si, @pi) then
  22.   begin
  23.     WaitForSingleObject(pi.hProcess, INFINITE);
  24.     CloseHandle(pi.hThread);
  25.     CloseHandle(pi.hProcess);
  26.  
  27.   end else
  28.   begin
  29.     // error handling, use GetLastError() to find out why CreateProcess() failed...
  30.   end;
  31. end;
  32. begin
  33. createdatabase;
  34.  
  35. end.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Start chrome Problem
« Reply #1 on: October 25, 2018, 03:11:45 pm »
Use TProcess class from Process unit.

Also the url is bit strange. You probably need a web server installed. Or created one by yourself using FPC faculties.

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: Start chrome Problem
« Reply #2 on: October 25, 2018, 03:16:39 pm »
i used it but there's no result and i used this little code :   :-[
Code: Pascal  [Select][+][-]
  1. rundll32 url.dll,FileProtocolHandler localhost/a.html

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12707
  • FPC developer.
Re: Start chrome Problem
« Reply #3 on: October 25, 2018, 03:27:05 pm »
Step one would be to fill in the comment about errorhandling with code that does something?

Also start is like a separate form of createprocess, that also takes certain parameters to do things (like show window).

Configuring both createprocess with options, AND use start seems to be a bit double.

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: Start chrome Problem
« Reply #4 on: October 25, 2018, 03:43:30 pm »
i just fix it with this :
Code: Pascal  [Select][+][-]
  1. comand :='C:\Program Files (x86)\Google\Chrome\Application\chrome.exe 127.0.0.1/a.html';

i want to know how can i start the a.html file in a hidden way that the new tab doesn't appear  %)

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Start chrome Problem
« Reply #5 on: October 25, 2018, 04:00:11 pm »
i just fix it with this :
Code: Pascal  [Select][+][-]
  1. comand :='C:\Program Files (x86)\Google\Chrome\Application\chrome.exe 127.0.0.1/a.html';

i want to know how can i start the a.html file in a hidden way that the new tab doesn't appear  %)

Sounds very fishy to me. What are you trying to accomplish?

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: Start chrome Problem
« Reply #6 on: October 25, 2018, 04:06:45 pm »

Thaddy

  • Hero Member
  • *****
  • Posts: 18765
  • To Europe: simply sell USA bonds: dollar collapses
Re: Start chrome Problem
« Reply #7 on: October 25, 2018, 05:27:22 pm »
chrome (and chromium-browser) has loads of command line options. One of them is
Code: Bash  [Select][+][-]
  1.  --app=<URL>

<URL> is the path. Chrome will start without toolbars (also known as kiosk mode)
That is probably what you mean.

Also note it is a bit annoying you use the AnsiString windows API. In your case it is better to use the UnicodeString API: W, not A.
There is - a lot - more wrong with youtr code, but start here. You will see that  --app=<URL> does what you want.
« Last Edit: October 25, 2018, 05:31:20 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: Start chrome Problem
« Reply #8 on: October 25, 2018, 05:30:22 pm »
i want to know how can i start the a.html file in a hidden way that the new tab doesn't appear  %)

Looks like you need to start a new browser window, so ...

First, as they say above, use TProcess and google for commandline options for chrome, (there are tons of them) particularly those which controls window behavior.

Second, if you want to show contents of local html-file your url should be in a form of
Code: [Select]
path/to/local/file.htmlBut if you want your html to be served by (local, or any other) webserver, your url should look like this:
Code: [Select]
http://localhost/path-as-it-served-by-webserver/file.html
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

Thaddy

  • Hero Member
  • *****
  • Posts: 18765
  • To Europe: simply sell USA bonds: dollar collapses
Re: Start chrome Problem
« Reply #9 on: October 25, 2018, 05:32:25 pm »
sash, posts crossed. I think he just means kiosk mode, which is like I wrote. Your tip may help too.
[edit]
example for chromium, but also works for chrome that returns your external ip from my servers in kiosk mode:
Code: Bash  [Select][+][-]
  1. chromium-browser --app=http://ip.thaddy.com

But that can also be a local path like file://xxxx/a.html
« Last Edit: October 25, 2018, 05:54:46 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018