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!
AngeloXAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.