Solved

finding a program

Posted on 2000-03-12
8
152 Views
Last Modified: 2010-04-04
i wanbt to know how can i know when my application is runnung if another application exists on my computer
i think that is something like findexecutable but i am having problem with the syntax ;
0
Comment
Question by:pascal_a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2611226
You can do this:

function GetProgramDir : string;
var
  Reg: TRegistry;
  TargetDir: string;

begin
  Result := '';

  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;  // Should be this by default anyway
    // Look initially for the project directory
    if Reg.OpenKeyReadOnly('\Software\Microsoft\Windows\CurrentVersion\App Paths\Fred.exe') then
      begin
      TargetDir := Reg.ReadString('');
      Reg.CloseKey;
      Result := ExtractFilePath(TargetDir);
      end;
  finally
    Reg.Free;
  end;
end;

Cheers,

Raymond.
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2611436
Are you talking about preventing mutiple program instances ??
0
 

Author Comment

by:pascal_a
ID: 2612658
no i am searching for another program while my application is running if it is not exists i need  to remove something from my program
0
Independent Software Vendors: 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!

 
LVL 1

Expert Comment

by:cobramania
ID: 2612844
If you know the caption title of the program, you can use this :

WindowName := FindWindow(nil,'Gangsters');
     If WindowName = 0 then
     begin
         //can't find the program
          MessageDlg('Run the game first',mtWarning,[mbOK],0);
          Application.Terminate;
     end
    else
    begin
          //if you find the program
    end;
     
0
 

Author Comment

by:pascal_a
ID: 2615243
i know the name of the program (something.exe) but this program is not running i want to know if i can make it to show something if the program exists from my program
i mean that if this program exists in my computer and is not an active window;
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2615249
Is Raymonds comment not what you need ?
0
 

Expert Comment

by:b26
ID: 2616141
U can use a couple of functions to find any file on your fixed drives, something like this:

function SearchFile(strfile:string): boolean ;
var c,c1: array [0..100] of char; blnok:boolean; i:integer;
    pstrdrives : LPSTR;
    nsize : DWORD;
    nrezult : WORD;
    strdrive:string;
begin
     SearchFile := false;
     nsize := 2;
     pstrdrives := LPSTR(HeapAlloc(GetProcessHeap, 0, nsize));
     nrezult := GetLogicalDriveStrings(nsize,pstrdrives);
     if nsize < nrezult then
     begin
        nsize := nrezult;
        pstrdrives := LPSTR(HeapReAlloc(GetProcessHeap, 0, pstrdrives, nsize));
        nrezult := GetLogicalDriveStrings(nsize,pstrdrives);
     end;
     if nrezult <> 0 then
     begin
          strdrive := '';
          for i:= 0 to nsize-1 do
              if pstrdrives[i] = #0  then
              begin
                   if (GetDriveType(LPSTR(strdrive)) = DRIVE_FIXED) and      SearchInDrive(strdrive,strfile) then
                   begin
                           SearchFile := true;
                           break
                   end;
                   strdrive := '';
                   if (i<nsize - 1) and (pstrdrives[i+1] = #0) then break;
              end
              else  strdrive := strdrive + pstrdrives[i];
     end;
     if(pstrdrives <> nil) then  HeapFree(GetProcessHeap, 0, pstrdrives);
end;


function SearchInDrive(strpath,strfile:string) : boolean;
var searchrec : TSearchRec;
    nfind : integer;
    var blnok: boolean;
begin
     SearchInDrive := false;
     nfind := Findfirst(strpath + strfile, faanyfile, searchrec);
     if nfind = 0 then
     begin
          SearchInDrive := true;
          FindClose(SearchRec);
          exit
     end
     else
     begin
         nfind := Findfirst(strpath + '*.*', faanyfile, searchrec);
         while nfind = 0 do
         begin
               if ((SearchRec.Attr and faDirectory) > 0) and (searchrec.name<>'.') and (searchrec.name<>'..') then
               begin
                    blnok := SearchinDrive(strpath + searchrec.name + '\',strfile);
                    if blnok then
                    begin
                       SearchInDrive := blnok;
                       FindClose(SearchRec);
                       exit
                    end
                    else nfind := Findnext(searchrec);
               end
               else nfind := Findnext(searchrec);
         end;
         FindClose(SearchRec);
     end;
end;

Cheers,
Bogdan
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 2887035
<LOCK>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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