Solved

ShellExecute

Posted on 2002-07-05
6
367 Views
Last Modified: 2010-04-04
I found this procedure to launch a program and it works fine, but when launching Word I want to open a saved dokument, so how do I write the parameter for the dokument?

procedure TForm1.Button1Click(Sender: TObject);
var startupinfo:Tstartupinfo;
    processinfo:Tprocessinformation;
    command: array [0..512] of Char;
    success:boolean  ;
    begin

strpcopy ( command,trim(edit1.text));
fillchar(startupinfo,sizeof(startupinfo),#0);
startupInfo.wShowWindow:=SW_SHOWNORMAL;
startupinfo.cb:=sizeof(startupinfo);
startupinfo.dwFlags:= STARTF_USESHOWWINDOW;
Success:= CreateProcess(nil,
      command,
      nil,
      nil,
      false,
      CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
      nil,
      nil,
      Startupinfo,
      Processinfo);
end;
0
Comment
Question by:rainbowsoftware
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7132563
your command could be like

'winword drive:\path\docname.suffix'

meikl ;-)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7132581
Hello
 
  CreateProcess will not open document without the defineing the exe , so in edit1 should look like 'c:\office\winword.exe c:\mydoc.doc'

if you would like to open document without define the application name, use ShellExecute

uses
  ShellApi;
procedure TForm1.Button3Click(Sender: TObject);
begin
  ShellExecute(Handle,'open',Pchar(Edit1.Text),nil,nil,SW_ShowNormal);
end;

if u still would like to use CreateProcess, you have to retrieve  the associated application from the windows registry first

Best regards
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 7132621
Hello again

  There's better way to retrieve the associated application using registry, it's FindExecutable API, I added it to ur code and now it's working fine, also don't forget to Close the handle for ur process and thread

uses ShellApi;
procedure TForm1.Button2Click(Sender: TObject);
var
  AppName: array[0..250] of char;
  startupinfo:Tstartupinfo;
  processinfo:Tprocessinformation;
  command: array [0..250] of Char;
  success:boolean  ;
begin
  FindExecutable(Pchar(Edit1.text),nil,(AppName));
  strpcopy ( command,trim(edit1.text));
  fillchar(startupinfo,sizeof(startupinfo),#0);
  startupInfo.wShowWindow:=SW_SHOWNORMAL;
  startupinfo.cb:=sizeof(startupinfo);
  startupinfo.dwFlags:= STARTF_USESHOWWINDOW;
  Success:= CreateProcess(nil,
     Pchar(AppName +' '+ command),
     nil,
     nil,
     false,
     CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
     nil,
     nil,
     Startupinfo,
     Processinfo);
// closing the handle for the process and thread
  CloseHandle(ProcessInfo.hProcess);
  CLoseHandle(ProcessInfo.hThread);
end;

Best regards
Mohammed Nasman
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 7132650
points are yours, mohammed,
you will then step over the 100k border :-))

meikl ;-)
0
 

Author Comment

by:rainbowsoftware
ID: 7133001
Thanks to Mohammed
This is perfectly working the way I wanted.
Joern
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7133025
you are welcome rainbowsoftware

Meikl, too far from 400K :o), wish to see you soon on 500k

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 96
Tidtcpserver listening on multiports? 1 35
Wincontrol not (correctly) drawn 15 40
firemonkey keyboard covers the controls 1 37
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question