• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 831
  • Last Modified:

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

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
QC20N
Asked:
QC20N
  • 5
  • 4
  • 2
  • +1
1 Solution
 
halejr1Commented:
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
 
Geert GOracle dbaCommented:
>>halejr1
answer to different question ?
0
 
Geert GOracle dbaCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
halejr1Commented:
my bad... sorry
0
 
QC20NAuthor Commented:
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
 
jyh1002Commented:
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
 
jyh1002Commented:
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
 
QC20NAuthor Commented:
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
 
QC20NAuthor Commented:
can you help me with this?
0
 
Geert GOracle dbaCommented:
that's a new Q ...
0
 
QC20NAuthor Commented:
:) I was hoping I could slink it in as a following up question.

But I will raise a new one.
0
 
Geert GOracle dbaCommented:
for 50 poinx again ?
0
 
QC20NAuthor Commented:
I have already raise another question. That is closed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now