VC program self-Deletion

Source: Internet
Author: User

ProgramYou can delete your own methods by using third parties. Otherwise, you can only add yourself to the bin and delete it after restart, or move yourself to the bin before exiting (use movefileex, pay special attention to the third parameter ).
The following describes how to delete a user by using a third party,CodeAs follows:

View code

 Void Deleteselfbycmd ()
{
Char Szcommandline [max_path] = { 0 };
Sprintf (szcommandline, " /C Ping 127.0.0.1-N 1 & del/f/Q \ "% s \" " , _ Pgmptr );
// Set yourself as quick exit
Setpriorityclass (getcurrentprocess (), realtime_priority_class );
Setthreadpriority (getcurrentthread (), thread_priority_time_critical );
ShellExecute (null, " Open " , " Cmd.exe " , Szcommandline, null, sw_hide );
Exitprocess ( 0 );
}

Void Deleteselfbyfile ()
{
// Take batch processing of BAT files as an Example
Const Char Szfilename [] = " Deletebat. bat " ;
Char Szdeletebattext [max_path];
Zeromemory (szdeletebattext, max_path );
Wsprintfa (szdeletebattext, " Ping 127.0.0.1-N 1 \ r \ ndel/Q \ "% s \" \ r \ ndel % 0 " , _ Pgmptr );
Handle hdelbatfile = createfilea (szfilename, generic_write, file_pai_write, null, create_always, file_attribute_normal, null );
If (Invalid_handle_value = hdelbatfile)
{
Closehandle (hdelbatfile );
Hdelbatfile = NULL;
Return ;
}
DWORD dwwrite ( 0 );
If ( 0 = Writefile (hdelbatfile, szdeletebattext, strlen (szdeletebattext), & dwwrite, null ))
{
Closehandle (hdelbatfile );
Hdelbatfile = NULL;
Return ;
}
Closehandle (hdelbatfile );
Hdelbatfile = NULL;
// Set yourself as quick exit
Setpriorityclass (getcurrentprocess (), realtime_priority_class );
Setthreadpriority (getcurrentthread (), thread_priority_time_critical );
ShellExecute (null, " Open " , " Deletebat. bat " , _ Pgmptr, null, sw_hide );
Exitprocess ( 0 );
}

To ensure that a third party can delete itself, it is best to set itself as a quick exit (). In addition, you can also add latency to a third party.
In addition, you can also use the vbs script to delete yourself. The idea is the same as deleting yourself through the BAT file. The vbs file content is as follows:

View code

Set objfso = Createobject ("Scripting. FileSystemObject")
If isexitafile ("D: \ test. TST")//Determine whether a file exists
Then deleteafile ("D: \ test. TST")
Objfso. deletefile wscript. scriptfullname//Delete yourself. wscript. scriptfullname returns the actual path of the script.

Header file # include <shellapi. h>
[Thank you for your reference]
... I forgot to record

 

 

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.