Solved

ShellExecute

Posted on 2002-07-05
6
361 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:mnasman
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:
mnasman 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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:mnasman
ID: 7133025
you are welcome rainbowsoftware

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

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now