|
저도 이게 필요해서..... 찾다가 내용을 보게 되었습니다. 그리고 devpia에서 찾아보다가 또 찾았는데 방법은 아주은 같은 것 같은데.... 아주 정교하고 확실한 것 같네요.... 제프리... 뭐뭐 아주 유명한 분이 추천하는 것이라 하더군요...
#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);
}
}
}
둥이네 님이 쓰신 글 :
: 어떻게 하다보니 인스톨 쉴드를 사용 안하고 수동으로 직접 파일을 지우는
: uninstall 프로그램을 사용하게 되었는데요.....
: 언인스톨을 하고 나면 언인스톨을 실행하는 실행 파일만 하나 덩그러니 폴더에 남아 있네요.
:
: 만약 testuninstall.exe 라는 프로그램이 있으면....
: 이걸 클릭하면 해당 디렉토리가 RemoveDir(const AnsiString Dir);
: 로 지워지는데..문제는..
: testuninstall.exe 자기 자신은 못지우네요..어쩌면 당연한건지도..
: test 란 폴더에 프로그램이 다있다면..
: testuninstall.exe. 를 제외한 모든 파일들은 다 삭제 되고.....나중에 test 폴더안에..testuninstall.exe 만 남아 있습니다.
: 윈도우가 c 를 포맷 못하는것처럼요...
: 그런데 이 파일이 은근히 신경 쓰이네요..
: 근데 왠지 방법은 있을꺼 같은데.....
: 인스톨 쉴드를 사용하면 좋을꺼 같은 생각도 들지만...
: 이왕이면 프로그램을 약간 수정해서 그대로 사용 했으면 합니다.
: 자기 자신도 삭제 가능한 프로그램
: 어떻게 하면 좋을지 의견이나 조언 부탁 드립니다.
|