Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set limit for run application

Posted on 2006-07-12
9
Medium Priority
?
289 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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