Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[15266] [질문,요청] 자기자신 삭제..
타향살이 [kyunghu] 2085 읽음    2014-08-23 11:44
자기 자신 삭제하는 것을 해보는데
팁에 있는 selfdelete 를 해봤는데 삭제가 안됩니다.

그래서 C++빌더 Q&A에 있는 박영목님이 올리신걸로 해보려고 하는데
이걸 Delphi로 바꿔주실 수 있나요 ?

#define DELUNSETUPBAT    __TEXT("\\DelUS.bat")

void WINAPI DeleteSelf () {
    HANDLE hfile;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
   
    hfile = CreateFile(DELUNSETUPBAT, GENERIC_WRITE, 0, NULL,
        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
    if (hfile != INVALID_HANDLE_VALUE) {
       
        TCHAR szBatFile[1000];
        TCHAR szUnsetupPathname[_MAX_PATH];
        TCHAR szUnsetupPath[_MAX_PATH];
        DWORD dwNumberOfBytesWritten;
       
        // Get the full pathname of our executable file.
        GetModuleFileName(NULL, szUnsetupPathname, _MAX_PATH);
       
        // Get the path of the executable file (without the filename)
        lstrcpy(szUnsetupPath, szUnsetupPathname);
        *strrchr(szUnsetupPath, __TEXT('\\')) = 0;    // Chop off the name
       
        // Construct the lines for the batch file.
        wsprintf(szBatFile,
            __TEXT(":Repeat\r\n")
            __TEXT("del \"%s\"\r\n")
            __TEXT("if exist \"%s\" goto Repeat\r\n")
            __TEXT("del \"%s\"\r\n"),
            szUnsetupPathname, szUnsetupPathname, DELUNSETUPBAT);
       
        // Write the batch file and close it.
        WriteFile(hfile, szBatFile, lstrlen(szBatFile) * sizeof(TCHAR),
            &dwNumberOfBytesWritten, NULL);
        CloseHandle(hfile);
       
        // Get ready to spawn the batch file we just created.
        ZeroMemory(&si, sizeof(si));
        si.cb = sizeof(si);
       
        // We want its console window to be invisible to the user.
        si.dwFlags = STARTF_USESHOWWINDOW;
        si.wShowWindow = SW_HIDE;
       
        // Spawn the batch file with low-priority and suspended.
        if (CreateProcess(NULL, DELUNSETUPBAT, NULL, NULL, FALSE,
            CREATE_SUSPENDED | IDLE_PRIORITY_CLASS, NULL,
            __TEXT("\\"), &si, &pi)) {
           
            // Lower the batch file's priority even more.
            SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE);
           
            // Raise our priority so that we terminate as quickly as possible.
            SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
            SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
           
            // Allow the batch file to run and clean-up our handles.
            CloseHandle(pi.hProcess);
            ResumeThread(pi.hThread);
            // We want to terminate right away now so that we can be deleted
            CloseHandle(pi.hThread);
        }
    }
}

+ -

관련 글 리스트
15266 [질문,요청] 자기자신 삭제.. 타향살이 2085 2014/08/23
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.