Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Prevent program from being executed.

Hey guys n gals,

How do I prevent a program from being executed.
I want to for example disable notepad.exe from being ran.
BTW, I only have the FileName of the program, so no WindowName.
Any ideas?

Thnx!
0
AngeloX
Asked:
AngeloX
  • 3
  • 2
  • 2
  • +2
3 Solutions
 
AngeloXAuthor Commented:
Hey thnx but the solution there isnt really what I wanted. No code that will edit the exe file with a password dialog and all that stuff.

I simply want a code that will stop a program from running if the filename is for example notepad.exe. That's all.

Thnx!
0
 
HypoviaxCommented:
I can only suggest to use this function and the latter code in a timer:

function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle,
FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;

This in a timer of interval 1ms

killtask('notepad.exe');

It effectively closes the program before it loads. However if someone posts a result that effectively prevents the exe not loading whatsoever then i am most interested.

Regards,

Hypoviax
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
esoftbgCommented:
Hey  AngeloX,
didn't you see the solution offered by Gwena and graded as an accepted answer:
http://www.geocities.com/gacarpenter386/pw-demo.zip
0
 
AngeloXAuthor Commented:
Hypoviax,

thnx but I already though of that too. Too much memory needed for a timer. Its not the right way to do.

Esoftbg,

that program will add binary to the exe and return the normal exe once everything is done. I dont want that.

For now the only way i guess is to let the program run the other exe in memory so the exe will be locked from running. But also that is not really the right way.

Anyone else any ideas?

Thnx!
0
 
esoftbgCommented:
O.k. Good luck !  I hope someone will provide the code what you need !
0
 
DragonSlayerCommented:
Have a look at madshi's example using his own madCodeHook unit: http://help.madshi.net/ProcessApi.htm

The above example shows a prompt asking if the user would like to execute a file. You can also modify it so that there is checking in the hook, and to see, let's say, if the process name is your target process, then you disable the execution (and optionally show an error if you want to), and as for other processes, just pass it on to the next hook.

Something like:

function IsBlackListedProcess(ProcessHandle: DWord): Boolean;
var
  pid: DWord;
  arrCh: array [0 .. MAX_PATH] of Char;
begin
  pid := ProcessHandleToId(ProcessHandle);
  Result := (pid <> 0) and ProcessIdToFileName(pid, arrCh) and
    (PosText('OurApplication.exe', arrCh) > 0);
end;

And if you would need to inject it as a systemwide hook, see http://help.madshi.net/HowToUseMadCodeHook.htm
0
 
DragonSlayerCommented:
madshi's packages cost USD150 (including source) but you may have the trial version to use (no source code) for personal and non-commercial use.

(Gee, i feel like i'm doing advertising for madshi, lol)
0
 
jaimexctsgCommented:
I read a book that has a registry hack to prevente any program from being executed. I cannot recall the exact procedure and did not buy the book, but it involves adding a registry Key, then using thet key to open all executables. Then writing another key to prevent execution of any program in the list. The list would be something like the MRU lists in the registry. So you can add or remove from it with a reg file.
 I remember it beeing about "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer...." thats all I can recall from the registry address. Then you had to add the key called someyhing like "PreventExecution" and the rest I really don't recall.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now