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