Solved

Set limit for run application

Posted on 2006-07-12
9
284 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
Industry Leaders: 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 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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 79
CheckListBox usage 3 82
Dev express lookupcombo 3 47
How to add columns to a RAD Studio FMX grid at design time 1 34
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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