Solved

Set limit for run application

Posted on 2006-07-12
9
279 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

18 Experts available now in Live!

Get 1:1 Help Now