?
Solved

delete file from task manager and also WINDOWS

Posted on 2009-07-09
9
Medium Priority
?
264 Views
Last Modified: 2013-11-23
I need to have me type in edit9.text a name that i know exists in the taskmanager. Then to click button 1 to delete it. However, when it deleted example test.exe to also read the info in edit9.text and delete that same file in windows folder, AFTER its been killed.

500 points  for full script pls im freakin way behind.
0
Comment
Question by:SonicM3
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:ccupo
ID: 24819374

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,Tlhelp32;
 
type
  TForm1 = class(TForm)
    Edit4: TEdit;
    Button1: TButton;
    function KillTask(ExeFileName: string): Integer;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
function TForm1.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;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
KillTask(Edit4.Text); // :)
end;
 
end.

Open in new window

0
 

Author Comment

by:SonicM3
ID: 24819496
thankyou friend, it kills the task, but it doesnt delete it from the windows folder. After the task has been killed it then has to read the text inside the edit4.text again and delete that filename in the WINDOWS folder.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24820489
way behind in what ?
0
Industry Leaders: 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!

 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24820491
of rewriting task manager ?
0
 

Author Comment

by:SonicM3
ID: 24822205
lads?  any help yet cheers.
0
 
LVL 1

Expert Comment

by:ccupo
ID: 24822273
unit Unit1;

interface

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, Tlhelp32, PsAPI;

type
    TForm1 = class(TForm)
        Edit4: TEdit;
        Button1: TButton;
        function KillTask(ExeFileName: string): integer;
        function ProcessFileName(PID: DWORD): string;
        // stdcall external 'Psapi.dll';

        // function GetProcessFullPathFileName(PID: DWORD): string;
        procedure Button1Click(Sender: TObject);
    private
        { Private declarations }
    public
        { Public declarations }
    end;

var
    Form1: TForm1;
    full_filename: string;

implementation

{$R *.dfm}

function TForm1.ProcessFileName(PID: DWORD): string;
var
    Handle: THandle;
begin
    Result := '';
    Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
    if Handle <> 0 then
        try
            SetLength(Result, MAX_PATH);
            begin
                if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
                    SetLength(Result, StrLen(PChar(Result)))
                else
                    Result := '';
            end;

        finally
            CloseHandle(Handle);
        end;
end;

function TForm1.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
        begin
            full_filename := ProcessFileName(FProcessEntry32.th32ProcessID);
            Result :=
                integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,
                BOOL(0),
                FProcessEntry32.th32ProcessID
                ),
                0
                )
                );
        end;
        ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    end;
    CloseHandle(FSnapshotHandle);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    KillTask(Edit4.Text);
    DeleteFile(full_filename);
end;




end.
0
 
LVL 1

Accepted Solution

by:
ccupo earned 2000 total points
ID: 24822284
sorry, take Code Snippet:
unit Unit1;
 
interface
 
uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, Tlhelp32, PsAPI;
 
type
    TForm1 = class(TForm)
        Edit4: TEdit;
        Button1: TButton;
        function KillTask(ExeFileName: string): integer;
        function ProcessFileName(PID: DWORD): string;
        // stdcall external 'Psapi.dll';
 
        // function GetProcessFullPathFileName(PID: DWORD): string;
        procedure Button1Click(Sender: TObject);
    private
        { Private declarations }
    public
        { Public declarations }
    end;
 
var
    Form1: TForm1;
    full_filename: string;
 
implementation
 
{$R *.dfm}
 
function TForm1.ProcessFileName(PID: DWORD): string;
var
    Handle: THandle;
begin
    Result := '';
    Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
    if Handle <> 0 then
        try
            SetLength(Result, MAX_PATH);
            begin
                if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
                    SetLength(Result, StrLen(PChar(Result)))
                else
                    Result := '';
            end;
 
        finally
            CloseHandle(Handle);
        end;
end;
 
function TForm1.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
        begin
            full_filename := ProcessFileName(FProcessEntry32.th32ProcessID);
            Result :=
                integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,
                BOOL(0),
                FProcessEntry32.th32ProcessID
                ),
                0
                )
                );
        end;
        ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    end;
    CloseHandle(FSnapshotHandle);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
    KillTask(Edit4.Text);
    DeleteFile(full_filename);
end;
 
 
 
 
end.

Open in new window

0
 

Author Comment

by:SonicM3
ID: 24824156
Thankyou, and i just wish i could give you more points for your hard work.
0
 

Author Closing Comment

by:SonicM3
ID: 31601882
excellent
0

Featured Post

Technology Partners: 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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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