#include <windows.h>
#include 
<tchar.h>
#include 
<stdio.h>
#include 
<shlobj.h>
#include 
<shlwapi.h>


BOOL SelfDelete()
{
    TCHAR szModule [MAX_PATH],
          szComspec[MAX_PATH],
          szParams [MAX_PATH];

    
// get file path names:
    if((GetModuleFileName(0,szModule,MAX_PATH)!=0&&
       (GetShortPathName(szModule,szModule,MAX_PATH)
!=0&&
       (GetEnvironmentVariable(
"COMSPEC",szComspec,MAX_PATH)!=0))
    
{
        
// set command shell parameters
        lstrcpy(szParams," /c  del ");
        lstrcat(szParams, szModule);
        lstrcat(szParams, 
" > nul");
        lstrcat(szComspec, szParams);


        
// set struct members
        STARTUPINFO        si={0};
        PROCESS_INFORMATION    pi
={0};
        si.cb 
= sizeof(si);
        si.dwFlags 
= STARTF_USESHOWWINDOW;
        si.wShowWindow 
= SW_HIDE;

        
// increase resource allocation to program
        SetPriorityClass(GetCurrentProcess(),
                REALTIME_PRIORITY_CLASS);
        SetThreadPriority(GetCurrentThread(),
            THREAD_PRIORITY_TIME_CRITICAL);

        
// invoke command shell
        if(CreateProcess(0, szComspec, 000,CREATE_SUSPENDED|
                    DETACHED_PROCESS, 
00&si, &pi))
        
{
            
// suppress command shell process until program exits
            SetPriorityClass(pi.hProcess,IDLE_PRIORITY_CLASS);
                        SetThreadPriority(pi.hThread,THREAD_PRIORITY_IDLE); 

            
// resume shell process with new low priority
            ResumeThread(pi.hThread);

            
// everything seemed to work
            return TRUE;
        }

        
else // if error, normalize allocation
        {
            SetPriorityClass(GetCurrentProcess(),
                             NORMAL_PRIORITY_CLASS);
            SetThreadPriority(GetCurrentThread(),
                              THREAD_PRIORITY_NORMAL);
        }

    }

    
return FALSE;
}

 
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
{
    
    TCHAR   sImeFile[MAX_PATH],
            szDir[MAX_PATH];


    MessageBox(NULL, _T(
"now delete myselef ?\n"), "Warning", MB_OK); 
    

//    if(!DelIMEFile(hInstance, sImeFile))
//        return FALSE;
    
//    DelReg();
    

       SelfDelete();

}
Posted on 2005-11-08 19:17 艾凡赫 阅读(631) 评论(0)  编辑 收藏 引用 所属分类: 好 玩

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理