?
Solved

Set limit for run application

Posted on 2006-07-12
9
Medium Priority
?
287 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
[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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1500 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

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!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

752 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