?
Solved

protect delphi application

Posted on 2007-11-16
5
Medium Priority
?
874 Views
Last Modified: 2012-06-27
HI experts.
I need to make a delphi application that can't be run by user only if it's called by my other delphi application. Is there a way to do this?
Thanks for help.

Cheers
0
Comment
Question by:A. Cristian Csiki
[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
5 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 1000 total points
ID: 20297443
see this code snippet. It returns the full path of the process called the running app, then you can check for this.

function TForm1.GetProcessParent(): string;
var
  snap: DWORD;
  pe32: PROCESSENTRY32;
 
  currprocid: DWORD;
  parentproc: DWORD;
  parentprocid: DWORD;
  parentpath: string;
  isparent: Boolean;
 
  time_currentproc: FILETIME;
 
  time_create: FILETIME;
  time_exit: FILETIME;
  time_kernel: FILETIME;
  time_user: FILETIME;
 
begin
  isparent := False;
 
  //create snapshot of all processes
  snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if snap <> INVALID_HANDLE_VALUE then
  begin
    pe32.dwSize := SizeOf(pe32);
 
    //walk through processes to find the current process info
    if Process32First(snap, pe32) then
    begin
      currprocid := GetCurrentProcessId(); //store current process id for faster access
      repeat
        if pe32.th32ProcessID = currprocid then
        begin
          //we've found the current process info
 
          {
           now we should compare current process start time with the parent process
           start time, to check if the parent process CAN be the real parent
           (process identifiers are reusable, so when the parent process terminates,
           any other process started later on can get the same ID)
          }
          GetProcessTimes(GetCurrentProcess(), time_create, time_exit, time_kernel, time_user);
          time_currentproc := time_create;
 
          parentprocid := pe32.th32ParentProcessID;
          parentproc := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, parentprocid);
          if parentproc <> 0 then
          begin
            if GetProcessTimes(parentproc, time_create, time_exit, time_kernel, time_user) then
            begin
              isparent := CompareFileTime(time_create, time_currentproc) < 0;
              {
               now we determined, that parentprocess CAN BE
               the parent of the current process
              }
 
              SetLength(parentpath, 1024); //1024 should be enough for the full path :)
              GetModuleFileNameEx(parentproc, 0, PChar(parentpath), 1024);
              parentpath := PChar(parentpath);
            end;
            CloseHandle(parentproc);
          end;
 
          break; //do not enumerate any further
        end;
      until not Process32Next(snap, pe32);
    end;
    CloseHandle(snap);
  end;
 
  if IsParent then
   result := ParentPath
  else
   result := '';
end;

Open in new window

0
 
LVL 6

Assisted Solution

by:den4b
den4b earned 1000 total points
ID: 20297494
1) You can make secondary application find any main applications (by process/window enumeration) and send them a custom (defined by you) message to notify that a new secondary app has been launched (passing process id for example). Main application will then check if it has launched that process, and send back a reply with a message which will tell secondary application if it needs to be terminated or has to continue running.

2) You could also use parameters to a secondary program for this task. For example, make your secondary program terminate if the required parameter wasn't sent to it. You could use some sort of an encoded date/time to call secondary app, and it will decode it and check that the time is within say 5 seconds of timestamp send to it.

There are loads of other ways to do it, but it’s up to you to pick/find the most suitable for you.
0
 
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20298011
Hi.
The thing I was looking is that mentioned by den4b : how do I receive data from delphi application? Clipbooard?

I think I got it. For a spellcheck and wright keywords I found this in google.:
http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htm

Thanks mites
0
 
LVL 6

Expert Comment

by:den4b
ID: 20298152

Yes, WM_COPYDATA is a generalized message which is used for passing data between applications. Use SendMessage() or PostMessage() function to pass that message with arbitrary data (pointers to data usually).

You can also use any custom user message, for example, define const: WM_MY_APP = WM_USER + 1 (any value actually between WM_USER and 0x7FFF).

Anyway, you are on the right direction now.
0
 
LVL 11

Author Comment

by:A. Cristian Csiki
ID: 20298370
Thanks.
Kind regards. ;)
0

Featured Post

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.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 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