1 BOOL DeleteSelf()
 2 {
 3  TCHAR szModule [MAX_PATH];  
 4  TCHAR szComspec[MAX_PATH];  
 5  TCHAR szParams [MAX_PATH];  
 6 
 7  // get file path names:   
 8  if((GetModuleFileName(0,szModule,MAX_PATH)!=0) &&  
 9   (GetShortPathName(szModule,szModule,MAX_PATH)!=0) &&  
10   (GetEnvironmentVariable("COMSPEC",szComspec,MAX_PATH)!=0))  
11  {  
12   // set command shell parameters   
13   lstrcpy(szParams," /c  del ");  
14   lstrcat(szParams, szModule);  
15   lstrcat(szParams, " > nul");  
16   lstrcat(szComspec, szParams);  
17 
18 
19   // set struct members   
20   STARTUPINFO     si={0};  
21   PROCESS_INFORMATION pi={0};  
22   si.cb = sizeof(si);  
23   si.dwFlags = STARTF_USESHOWWINDOW;  
24   si.wShowWindow = SW_HIDE;  
25 
26   // increase resource allocation to program   
27   SetPriorityClass(GetCurrentProcess(),  
28    REALTIME_PRIORITY_CLASS);  
29   SetThreadPriority(GetCurrentThread(),  
30    THREAD_PRIORITY_TIME_CRITICAL);  
31 
32   // invoke command shell   
33   if(CreateProcess(0, szComspec, 0, 0, 0,CREATE_SUSPENDED|  
34    DETACHED_PROCESS, 0, 0, &si, &pi))  
35   {  
36    // suppress command shell process until program exits   
37    SetPriorityClass(pi.hProcess,IDLE_PRIORITY_CLASS);  
38    SetThreadPriority(pi.hThread,THREAD_PRIORITY_IDLE);   
39 
40    // resume shell process with new low priority   
41    ResumeThread(pi.hThread);  
42 
43    // everything seemed to work   
44    return TRUE;  
45   }  
46   else // if error, normalize allocation   
47   {  
48    SetPriorityClass(GetCurrentProcess(),  
49     NORMAL_PRIORITY_CLASS);  
50    SetThreadPriority(GetCurrentThread(),  
51     THREAD_PRIORITY_NORMAL);  
52   }  
53  }  
54  return FALSE;  
55 
56 }