Solved

Set limit for run application

Posted on 2006-07-12
9
280 Views
Last Modified: 2010-04-05
hi
how i can Block run application ( for example "Notepad.exe" can't run if i set Access limit for this )
0
Comment
Question by:mahdiparak
9 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17094408
I guess you want to do it for your application... Let's say you store a value in the registry and each time you run the application you increase the value (by default it should be 0).

You can also update resourse string inside your EXE if you don't want to use the Registry...
0
 
LVL 1

Expert Comment

by:Tueblo
ID: 17095323
If you want your own application only to start one time, you can use a mutex. Like:

uses Windows;

var mutex: THandle;

initialization
  mutex := CreateMutex(NIL, TRUE, PChar('myProgramID'));
  if ( GetLastError = ERROR_ALREADY_EXISTS ) then Halt;

finalization
 if ( mutex <> 0 ) then CloseHandle(mHandle);

For limiting the number of instances of any other application, I would check regularly and terminate the extra instances. Maybe by calling the following function once in a while:

uses TlHelp32, Windows;

procedure LimitRunningInstances(exeName: String; limit: Integer);
var handle       : THandle;
    processEntry : TProcessEntry32;
    quantity     : Integer;
begin
  processEntry.dwSize := sizeOf(processEntry);
  handle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  try
    Process32First(handle, processEntry);
    quantity := 0;
    repeat
      if ( AnsiUpperCase(exeName) = AnsiUpperCase(processEntry.szExeFile) ) then
      begin
        INC(quantity);
        if ( quantity > limit ) then
          TerminateProcess(OpenProcess(PROCESS_TERMINATE, FALSE, processEntry.th32ProcessID), 0);
      end;
    until (not Process32Next(handle, processEntry));
  finally
    CloseHandle(handle);
  end;
end;

0
 
LVL 11

Expert Comment

by:calinutz
ID: 17097185
I think you mean that you want to stop other applications from running... not your own.
You want to build an application that would control what applications are allowed to run?
Am I right?
0
 
LVL 11

Expert Comment

by:calinutz
ID: 17097205
I suggest you build an application that checks if they are running (the applications that you want to limit) and kill them if found. To kill processes check this out:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20419877.html

Regards
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:calinutz
ID: 17097231
Also you could kill it this way too:
(kills the first instance encountered. place it in a loop to kill all notepads)
 procedure KillNotepad;
Var
  H   : HWND;
  PID : Cardinal;
  PH  : Cardinal;
Begin
  H := FindWindow('Notepad', nil);
  If H > 0 Then Begin
    GetWindowThreadProcessId(H, @PID);
    PH := OpenProcess(PROCESS_TERMINATE, False, PID);
    TerminateProcess(PH, 0);
    CloseHandle(PH);
  End;
End;
0
 
LVL 6

Expert Comment

by:saravananvg
ID: 17098210
Hello Sir,

  Check the following link to kill an unwanted process.

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21813785.html

with regards,
padmaja.
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17098251
thanks all
but i want to set block befor start a application
0
 
LVL 1

Author Comment

by:mahdiparak
ID: 17098268
i want Blocking an application before it starts
0
 
LVL 5

Accepted Solution

by:
Scay7 earned 500 total points
ID: 17103138
In order to block an application from running there are a couple of ways
1. windows policies
2. disable the run command
3. make an application that traps the csrss.exe and the rundll32.exe
4. make your own explorer.exe

1. Create a user group with loads of restrictions
2. http://delphi.about.com/od/windowsshellapi/l/aa081703a.htm
3. Youll need some form of injection program that moniters them
4. too big a task... :P

peace Scay7
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

12 Experts available now in Live!

Get 1:1 Help Now