Q&A

  • 현재 실행하고 있는 나 자신의 프로세스와 파일을 죽이는법?
현재 실행되고 있는 주체의 파일과 프로세스를 죽이는 법이 있나요?



만약 c:test.exe를 더블클릭해서 실행하는데 이 test.exe가 하고 싶은 일이 c:test.exe파일을 지우고 싶은데 어떻게 하면 되나요?



고수님들의 답변 부탁드립니당....

1  COMMENTS
  • Profile
    Ziker 2001.07.05 00:06
    안녕하세요 지커(김성규)입니다.



    이 게시판에서 이전에 올라온 질문 내용의 답변을 발췌한 것입니다.





    program SelfModifier; (* Looks for a const and alters it *)

    (* Puts paramstr(1) into Name *)



    const

    Name : string = 'Fix me up'; {get 256 bytes to play with}

    type

    Buffer = array[0..$3fff] of byte;

    var

    ExeFile : file;

    P : ^Buffer;

    N,I,O : word;

    NStr : string;



    begin

    begin

    new(P); {get mem for our buffer}

    assign(ExeFile,paramstr(0)); {get myself}

    reset(ExeFile,1);

    blockread(ExeFile,P^,sizeof(Buffer),N);

    close(ExeFile); {got it into Buf, now close it}

    O:=(dseg-cseg+word(P^[8])) shl 4; {start of data seg in exe file}

    writeln('Name: ',Name);

    NStr := paramstr(1); {new string to put in Name}

    inc(O,ofs(Name)); {where Name is located}

    move(NStr[0],P^[O],length(NStr)+1); {move string incl. length byte}

    rewrite(ExeFile,1); {create new version}

    blockwrite(ExeFile,P^,N); {write it}

    close(ExeFile); {close it...}

    dispose(P) {...and release mem}

    end

    end.





    procedure DeleteMe;

    var

    BatchFile: TextFile;

    BatchFileName: string;

    ProcessInfo: TProcessInformation;

    StartUpInfo: TStartupInfo;

    begin

    { create a batchfile in the applications directory }

    BatchFileName := ExtractFilePath(ParamStr(0)) + '$$336699.bat';



    { open and write the file }

    AssignFile(BatchFile, BatchFileName);

    Rewrite(BatchFile);



    Writeln(BatchFile, ':try');

    Writeln(BatchFile, 'del "' + ParamStr(0) + '"');

    Writeln(BatchFile,

    'if exist "' + ParamStr(0) + '"' + ' goto try');

    Writeln(BatchFile, 'del "' + BatchFileName + '"');

    CloseFile(BatchFile);



    FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);

    StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;

    StartUpInfo.wShowWindow := SW_HIDE;



    if CreateProcess(nil, PChar(BatchFileName), nil, nil,

    False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,

    ProcessInfo) then

    begin

    CloseHandle(ProcessInfo.hThread);

    CloseHandle(ProcessInfo.hProcess);

    end;

    end;







    진짜초보 wrote:

    > 현재 실행되고 있는 주체의 파일과 프로세스를 죽이는 법이 있나요?

    >

    > 만약 c:test.exe를 더블클릭해서 실행하는데 이 test.exe가 하고 싶은 일이 c:test.exe파일을 지우고 싶은데 어떻게 하면 되나요?

    >

    > 고수님들의 답변 부탁드립니당....