Self-deletion of programs under Windows

Source: Internet
Author: User
Tags sprintf

There are many ways to do self-deletion, the most common is to implement the self-deletion through batch processing.

Batch processing enables the ability to delete itself after running.

Lets the program create batches, which are then removed by the batch process and the batch itself.

: Loop del "D:\Program file\ ..."  ifexist  goto  loopdel%0

The functions used to create and run batch files are also different, and here's my personal example.

1#include <Windows.h>2#include <stdio.h>3 4 intMain ()5 {6  Charszfile[_max_path]={0}; 7  CharSztem[max_path];8  CharSzdelcat[max_path];9GetModuleFileName (Null,szfile,max_path);//gets the absolute path of the programTen   Onestrcpy (Szdelcat,": loop\r\n"); Asprintf (Sztem,"del \ "%s\" \ r \ n", szfile); - strcat (szdelcat,sztem); -sprintf (Sztem,"if exist \ "%s\" goto loop\r\n", szfile); the strcat (szdelcat,sztem); -sprintf (Sztem,"del%%0\r\n"); - strcat (szdelcat,sztem); -   +  Charszbat[max_path]="Del.bat";//Batch file name -HANDLE hbatfile = CreateFile (Szbat, Generic_write,0,0, Create_always,0,0);  +    A DWORD Dwnum;  atWriteFile (Hbatfile, Szdelcat, Lstrlen (szdelcat) +1, &Dwnum, NULL);  - CloseHandle (Hbatfile);  -ShellExecute (0,0, Szbat,0,0, sw_hide); -ExitProcess (0); -  return 0; -}

When using strcat to connect two strings, it is important to note that if the target string is not assigned, the first copied string should use the strcpy function to the specified location.

Self-deletion of programs under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.