?
Solved

How can I run application from "c:\program files" by using ShellExecute?

Posted on 2009-02-12
13
Medium Priority
?
805 Views
Last Modified: 2013-11-23
How can I run application from "c:\program files" by using ShellExecute?

And instead of using "c:\program files" I would like to use DOS parameters such as %programfiles%

Thank you.
0
Comment
Question by:QC20N
  • 5
  • 4
  • 2
  • +1
13 Comments
 
LVL 8

Expert Comment

by:halejr1
ID: 23623127
couple of things to consider, but first and foremost is how are you using this and what is the scope of deployment.

One time:
 c:\progra~1\dir\dir\executable.exe

the syntax takes the first 6 characters, then a ~, and then a number indicating a reference if there are more than one similarly named directories.  i.e. program files; program list; etc. etc.  Now we know for the most part, we may only encounter 'program files' at the root of the directory with no other similar directory names.  If we were using a custom directory structure where we have directories called  "database files" "database elements" "database structures" they would be refered to in the following order:

databa~1 = database elements
databa~2 = database files
databa~3 = database structures

if you are deploying an application on a box, why not create a reference variable i.e.
set applicationfiles=c:\application files
and now you can refer to %applicationfiles%

I think that might work as well.

Let me know.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23623517
>>halejr1
answer to different question ?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23623630
var action, filename, path: string;
begin
  action := 'open';
  filename := 'text.txt';
  path := PathToProgramFiles;
  ShellExecute(0, PChar(action), PChar(filename), nil, PChar(path), SW_SHOWNORMAL);
end;
uses ShlObj;
 
function PathToMyDocuments: string;
var
  Path : pchar;
  idList : PItemIDList;
begin
  GetMem(Path, MAX_PATH);
  try
    SHGetSpecialFolderLocation(0, CSIDL_PERSONAL, idList);
    SHGetPathFromIDList(idList, Path);
    Result := string(Path);
  finally
    FreeMem(Path);
  end;
end;
 
function PathToProgramFiles: string;
var
  Path : pchar;
  idList : PItemIDList;
begin
  GetMem(Path, MAX_PATH);
  try
    SHGetSpecialFolderLocation(0, CSIDL_PROGRAMS, idList);
    SHGetPathFromIDList(idList, Path);
    Result := string(Path);
  finally
    FreeMem(Path);
  end;
end;

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:halejr1
ID: 23623688
my bad... sorry
0
 

Author Comment

by:QC20N
ID: 23624077
I copy and paste the functions.

I can't get it to work.
procedure TForm1.ListBox1DblClick(Sender: TObject);
var str, action, filename, path: string;
begin
  action := 'open';
  filename := 'DameWare Development\DameWare Mini Remote Control\dwrcc.exe';
  path := PathToProgramFiles;
  ShellExecute(0, PChar(action), PChar(filename), nil, PChar(path), SW_SHOWNORMAL);
end;

Open in new window

0
 
LVL 1

Accepted Solution

by:
jyh1002 earned 200 total points
ID: 23625859
You might need to use GetEnvironmentVariable
uses SysUtils, ShellAPI
 
procedure TForm1.Button1Click(Sender: TObject);
var fileName: string;
begin
  fileName := IncludeTrailingBackSlash(GetEnvironmentVariable('ProgramFiles')) + 'Internet Explorer\iexplore.exe';
  ShellExecute(0, 'open', PChar(fileName), nil, nil, SW_SHOWNORMAL);
end;

Open in new window

0
 
LVL 1

Expert Comment

by:jyh1002
ID: 23625953
You could call SysUtils.GetEnvironmentVariable with following variables

ALLUSERSPROFILE
APPDATA
CLIENTNAME
CommonProgramFiles
COMPUTERNAME
ComSpec
HOMEDRIVE
HOMEPATH
LOGONSERVER
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PCToolsDir
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVEL
PROCESSOR_REVISION
ProgramFiles
SESSIONNAME
SystemDrive
SystemRoot
TEMP
TMP
USERDOMAIN
USERNAME
USERPROFILE
WINDIR
0
 

Author Comment

by:QC20N
ID: 23627016
Perfect, Thx.

Maybe a small question. How do you add parameters to the application I want to run?

I know it can accept parameters, cause I can run it from the commandline.
0
 

Author Comment

by:QC20N
ID: 23631154
can you help me with this?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23631165
that's a new Q ...
0
 

Author Comment

by:QC20N
ID: 23631256
:) I was hoping I could slink it in as a following up question.

But I will raise a new one.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23641428
for 50 poinx again ?
0
 

Author Comment

by:QC20N
ID: 23642752
I have already raise another question. That is closed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

840 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